fixed mistake reported by William, caused by updating the lua.cxx

but not the lua.swg file


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8534 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Mark Gossage 2006-01-24 04:47:46 +00:00
commit c413035b7c
3 changed files with 40 additions and 49 deletions

View file

@ -1,6 +1,14 @@
Version 1.3.28 (unreleased). Version 1.3.28 (unreleased).
=========================== ===========================
01/24/2006: mgossage
- Removed the type swig_lua_command_info & replace with luaL_reg
(which then broke the code), fixed this
- added an additional cast in the typemaps for enum's
due to the issue that VC.Net will not allow casting of
a double to an enum directly. Therefore cast to int then to enum
(thenks to Jason Rego for this observation)
01/16/2006: mmatus (Change disabled) 01/16/2006: mmatus (Change disabled)
Add initial support for regexp via the external library Add initial support for regexp via the external library
RxSpencer. SWIG doesn't require this library to compile RxSpencer. SWIG doesn't require this library to compile

View file

@ -31,15 +31,26 @@
%typemap(in,checkfn="lua_isnumber") int,short,long, %typemap(in,checkfn="lua_isnumber") int,short,long,
unsigned int,unsigned short,unsigned long, unsigned int,unsigned short,unsigned long,
signed char,unsigned char, signed char,unsigned char,
float,double,enum SWIGTYPE float,double
%{$1 = ($type)lua_tonumber(L, $input);%} %{$1 = ($type)lua_tonumber(L, $input);%}
%typemap(out) int,short,long, %typemap(out) int,short,long,
unsigned int,unsigned short,unsigned long, unsigned int,unsigned short,unsigned long,
signed char,unsigned char, signed char,unsigned char,
float,double,enum SWIGTYPE float,double
%{ lua_pushnumber(L, (double) $1); SWIG_arg++;%} %{ lua_pushnumber(L, (double) $1); SWIG_arg++;%}
/* enums have to be handled slightly differently
VC++ .net will not allow a cast from double to enum directly
therefore cast to an int first.
Thanks to Jason Rego <JasonR@rainbowstudios.com> for finding this.
*/
%typemap(in,checkfn="lua_isnumber") enum SWIGTYPE
%{$1 = ($type)(int)lua_tonumber(L, $input);%}
%typemap(out) enum SWIGTYPE
%{ lua_pushnumber(L, (double)(int)($1)); SWIG_arg++;%}
// boolean (which is a special type in lua) // boolean (which is a special type in lua)
// note: 1 & 0 are not booleans in lua, only true & false // note: 1 & 0 are not booleans in lua, only true & false
%typemap(in,checkfn="lua_isboolean") bool %typemap(in,checkfn="lua_isboolean") bool
@ -429,8 +440,11 @@ SWIGEXPORT int SWIG_init(lua_State* L)
SWIG_Lua_module_begin(L,SWIG_name); SWIG_Lua_module_begin(L,SWIG_name);
/* add commands/functions */ /* add commands/functions */
for (i = 0; swig_commands[i].name; i++){ for (i = 0; swig_commands[i].name; i++){
SWIG_Lua_module_add_function(L,swig_commands[i].name,swig_commands[i].wrapper); SWIG_Lua_module_add_function(L,swig_commands[i].name,swig_commands[i].func);
} }
/*luaL_openlib(L,NULL,swig_commands,0);*/
/* all in one */
/*luaL_openlib(L,SWIG_name,swig_commands,0);*/
/* add variables */ /* add variables */
for (i = 0; swig_variables[i].name; i++){ for (i = 0; swig_variables[i].name; i++){
SWIG_Lua_module_add_variable(L,swig_variables[i].name,swig_variables[i].get,swig_variables[i].set); SWIG_Lua_module_add_variable(L,swig_variables[i].name,swig_variables[i].get,swig_variables[i].set);
@ -447,8 +461,8 @@ SWIGEXPORT int SWIG_init(lua_State* L)
SWIG_Lua_InstallConstants(L,swig_constants); SWIG_Lua_InstallConstants(L,swig_constants);
/* end module */ /* end module */
SWIG_Lua_module_end(L); /*SWIG_Lua_module_end(L);*/
lua_pop(L,1); /* tidy stack (remove module table)*/
lua_pop(L,1); /* tidy stack (remove global table)*/ lua_pop(L,1); /* tidy stack (remove global table)*/
return 1; return 1;

View file

@ -14,7 +14,6 @@ extern "C" {
#include "lua.h" #include "lua.h"
#include "lauxlib.h" #include "lauxlib.h"
/*#include "stdio.h" debug printing */
#include <assert.h> /* for a few sanity tests */ #include <assert.h> /* for a few sanity tests */
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -27,20 +26,17 @@ extern "C" {
#define SWIG_LUA_POINTER 4 #define SWIG_LUA_POINTER 4
#define SWIG_LUA_BINARY 5 #define SWIG_LUA_BINARY 5
/* type for all wrapper fns */ /* Structure for command table (replaced by luaLib's luaL_reg) */
typedef int (*swig_lua_wrapper_func)(lua_State*); /*typedef struct {
/* Structure for command table */
typedef struct {
const char *name; const char *name;
swig_lua_wrapper_func wrapper; lua_CFunction wrapper;
} swig_lua_command_info; } swig_lua_command_info;*/
/* Structure for variable linking table */ /* Structure for variable linking table */
typedef struct { typedef struct {
const char *name; const char *name;
swig_lua_wrapper_func get; lua_CFunction get;
swig_lua_wrapper_func set; lua_CFunction set;
} swig_lua_var_info; } swig_lua_var_info;
/* Constant information structure */ /* Constant information structure */
@ -55,19 +51,19 @@ typedef struct {
typedef struct { typedef struct {
const char *name; const char *name;
swig_lua_wrapper_func method; lua_CFunction method;
} swig_lua_method; } swig_lua_method;
typedef struct { typedef struct {
const char *name; const char *name;
swig_lua_wrapper_func getmethod; lua_CFunction getmethod;
swig_lua_wrapper_func setmethod; lua_CFunction setmethod;
} swig_lua_attribute; } swig_lua_attribute;
typedef struct swig_lua_class { typedef struct swig_lua_class {
const char *name; const char *name;
swig_type_info **type; swig_type_info **type;
swig_lua_wrapper_func constructor; lua_CFunction constructor;
void (*destructor)(void *); void (*destructor)(void *);
swig_lua_method *methods; swig_lua_method *methods;
swig_lua_attribute *attributes; swig_lua_attribute *attributes;
@ -112,26 +108,6 @@ typedef struct {
lua_pushcfunction(L, f), \ lua_pushcfunction(L, f), \
lua_rawset(L,-3)) lua_rawset(L,-3))
/* debug routine*/
#if 0
#define DEBUG_PRINT(X) {printf(X);fflush(stdout);}
#define DEBUG_STACK(X) {swig_print_stack(L);}
void swig_print_stack(lua_State* L)
{
int i=lua_gettop(L);
printf("stack is size %d==============\n",i);
for( ; i>0;i--)
printf(" %d %p(%s)\n",i,lua_topointer(L,i),lua_typename(L,lua_type(L,i)));
printf("end stack==============\n");
fflush(stdout);
}
#else
#define DEBUG_PRINT(X) {}
#define DEBUG_STACK(X) {}
#endif
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* global variable support code: modules * global variable support code: modules
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -230,7 +206,7 @@ SWIGINTERN void SWIG_Lua_module_end(lua_State* L)
} }
/* adding a linked variable to the module */ /* adding a linked variable to the module */
SWIGINTERN void SWIG_Lua_module_add_variable(lua_State* L,const char* name,swig_lua_wrapper_func getFn,swig_lua_wrapper_func setFn) SWIGINTERN void SWIG_Lua_module_add_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn)
{ {
assert(lua_istable(L,-1)); /* just in case */ assert(lua_istable(L,-1)); /* just in case */
lua_getmetatable(L,-1); /* get the metatable */ lua_getmetatable(L,-1); /* get the metatable */
@ -250,7 +226,7 @@ SWIGINTERN void SWIG_Lua_module_add_variable(lua_State* L,const char* name,swig_
} }
/* adding a function module */ /* adding a function module */
SWIGINTERN void SWIG_Lua_module_add_function(lua_State* L,const char* name,swig_lua_wrapper_func fn) SWIGINTERN void SWIG_Lua_module_add_function(lua_State* L,const char* name,lua_CFunction fn)
{ {
SWIG_Lua_add_function(L,name,fn); SWIG_Lua_add_function(L,name,fn);
} }
@ -289,8 +265,6 @@ SWIGINTERN int SWIG_Lua_class_get(lua_State* L)
lua_pushvalue(L,2); /* key */ lua_pushvalue(L,2); /* key */
lua_rawget(L,-2); /* look for the fn */ lua_rawget(L,-2); /* look for the fn */
lua_remove(L,-2); /* stack tidy, remove .fn table */ lua_remove(L,-2); /* stack tidy, remove .fn table */
DEBUG_PRINT("check .fn\n");
DEBUG_STACK(L);
if (lua_iscfunction(L,-1)) if (lua_iscfunction(L,-1))
{ /* found it so return the fn & let lua call it */ { /* found it so return the fn & let lua call it */
lua_remove(L,-2); /* stack tidy, remove metatable */ lua_remove(L,-2); /* stack tidy, remove metatable */
@ -300,15 +274,12 @@ SWIGINTERN int SWIG_Lua_class_get(lua_State* L)
/* NEW: looks for the __getitem() fn /* NEW: looks for the __getitem() fn
this is a user provided get fn */ this is a user provided get fn */
SWIG_Lua_get_table(L,"__getitem"); /* find the __getitem fn */ SWIG_Lua_get_table(L,"__getitem"); /* find the __getitem fn */
DEBUG_PRINT("check __getitem\n");
DEBUG_STACK(L);
if (lua_iscfunction(L,-1)) /* if its there */ if (lua_iscfunction(L,-1)) /* if its there */
{ /* found it so call the fn & return its value */ { /* found it so call the fn & return its value */
lua_pushvalue(L,1); /* the userdata */ lua_pushvalue(L,1); /* the userdata */
lua_pushvalue(L,2); /* the parameter */ lua_pushvalue(L,2); /* the parameter */
lua_call(L,2,1); /* 2 value in (userdata),1 out (result) */ lua_call(L,2,1); /* 2 value in (userdata),1 out (result) */
lua_remove(L,-2); /* stack tidy, remove metatable */ lua_remove(L,-2); /* stack tidy, remove metatable */
/*DEBUG_STACK(L); */
return 1; return 1;
} }
return 0; /* sorry not known */ return 0; /* sorry not known */
@ -368,8 +339,6 @@ SWIGINTERN int SWIG_Lua_class_destruct(lua_State* L)
(1) userdata (not the meta table) */ (1) userdata (not the meta table) */
swig_lua_userdata* usr; swig_lua_userdata* usr;
swig_lua_class* clss; swig_lua_class* clss;
DEBUG_PRINT("SWIG_Lua_class_destruct\n");
DEBUG_STACK(L);
assert(lua_isuserdata(L,-1)); /* just in case */ assert(lua_isuserdata(L,-1)); /* just in case */
usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */ usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
/* if must be destroyed & has a destructor */ /* if must be destroyed & has a destructor */
@ -412,7 +381,7 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname)
} }
/* helper add a variable to a registered class */ /* helper add a variable to a registered class */
SWIGINTERN void SWIG_Lua_add_class_variable(lua_State* L,const char* name,swig_lua_wrapper_func getFn,swig_lua_wrapper_func setFn) SWIGINTERN void SWIG_Lua_add_class_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn)
{ {
assert(lua_istable(L,-1)); /* just in case */ assert(lua_istable(L,-1)); /* just in case */
SWIG_Lua_get_table(L,".get"); /* find the .get table */ SWIG_Lua_get_table(L,".get"); /* find the .get table */