Add support for eLua including options for Lua Tiny RAM (LTR)

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12813 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2011-09-16 22:53:35 +00:00
commit 91d22324e7
6 changed files with 217 additions and 30 deletions

View file

@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.5 (in progress) Version 2.0.5 (in progress)
=========================== ===========================
2011-09-14: wsfulton
[Lua] Patch #3408012 from Raman Gopalan - add support for embedded Lua (eLua)
including options for targeting Lua Tiny RAM (LTR).
2011-09-14: wsfulton 2011-09-14: wsfulton
[C#] Add boost_intrusive_ptr.i library contribution from patch #3401571. [C#] Add boost_intrusive_ptr.i library contribution from patch #3401571.

View file

@ -54,6 +54,7 @@ Past SWIG developers and major contributors include:
Duncan Temple Lang (R) Duncan Temple Lang (R)
Miklos Vajna <vmiklos@frugalware.org> (PHP directors) Miklos Vajna <vmiklos@frugalware.org> (PHP directors)
Mark Gossage (mark@gossage.cjb.net) (Lua) Mark Gossage (mark@gossage.cjb.net) (Lua)
Raman Gopalan (ramangopalan@gmail.com) (eLua)
Gonzalo Garramuno (ggarra@advancedsl.com.ar) (Ruby, Ruby's UTL) Gonzalo Garramuno (ggarra@advancedsl.com.ar) (Ruby, Ruby's UTL)
John Lenz (Guile, MzScheme updates, Chicken module, runtime system) John Lenz (Guile, MzScheme updates, Chicken module, runtime system)
Ian Lance Taylor (Go) Ian Lance Taylor (Go)

View file

@ -5,6 +5,30 @@
* This file is parsed by SWIG before reading any other interface file. * This file is parsed by SWIG before reading any other interface file.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
%insert("runtime") %{
/* Lua flavors */
#define SWIG_LUA_LUA 1
#define SWIG_LUA_ELUA 2
#define SWIG_LUA_ELUAC 3
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
# define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0
# define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0
# define SWIG_LUA_CONSTTAB_STRING(B, C) SWIG_LUA_STRING, (char *)B, 0, 0, (void *)C, 0
# define SWIG_LUA_CONSTTAB_CHAR(B, C) SWIG_LUA_CHAR, (char *)B, (long)C, 0, 0, 0
# else
# define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C)
# define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
# define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
# define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
#endif
#if (SWIG_LUA_TARGET == SWIG_LUA_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_ELUAC)
# define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING}
# define LSTRVAL LRO_STRVAL
#endif
%}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* includes * includes
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -18,27 +42,27 @@
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
// this basically adds to a table of constants // this basically adds to a table of constants
%typemap(consttab) int, unsigned int, short, unsigned short, long, unsigned long, unsigned char, signed char, bool, enum SWIGTYPE %typemap(consttab) int, unsigned int, short, unsigned short, long, unsigned long, unsigned char, signed char, bool, enum SWIGTYPE
{ SWIG_LUA_INT, (char *)"$symname", (long) $value, 0, 0, 0} {SWIG_LUA_CONSTTAB_INT("$symname", $value)}
%typemap(consttab) float, double %typemap(consttab) float, double
{ SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) $value, 0, 0} {SWIG_LUA_CONSTTAB_FLOAT("$symname", $value)}
%typemap(consttab) long long, unsigned long long, signed long long %typemap(consttab) long long, unsigned long long, signed long long
{ SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) $value, 0, 0} {SWIG_LUA_CONSTTAB_FLOAT("$symname", $value)}
%typemap(consttab) const long long&, const unsigned long long&, const signed long long& %typemap(consttab) const long long&, const unsigned long long&, const signed long long&
{ SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) *$value, 0, 0} {SWIG_LUA_CONSTTAB_FLOAT("$symname", *$value)}
%typemap(consttab) char *, const char *, char [], const char [] %typemap(consttab) char *, const char *, char [], const char []
{ SWIG_LUA_STRING, (char *)"$symname", 0, 0, (void *)$value, 0} {SWIG_LUA_CONSTTAB_STRING("$symname", $value)}
// note: char is treated as a seperate special type // note: char is treated as a seperate special type
// signed char & unsigned char are numbers // signed char & unsigned char are numbers
%typemap(consttab) char %typemap(consttab) char
{ SWIG_LUA_CHAR, (char *)"$symname", (long)$value, 0, 0, 0} {SWIG_LUA_CONSTTAB_CHAR("$symname", $value)}
%typemap(consttab) long long, unsigned long long %typemap(consttab) long long, unsigned long long
{ SWIG_LUA_STRING, (char *) "$symname", 0, 0, (void *)"$value", 0} {SWIG_LUA_CONSTTAB_STRING("$symname", "$value")}
%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE [] %typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE []
{ SWIG_LUA_POINTER, (char *)"$symname", 0, 0, (void *)$value, &$1_descriptor} { SWIG_LUA_POINTER, (char *)"$symname", 0, 0, (void *)$value, &$1_descriptor}

View file

@ -181,12 +181,24 @@ SWIGINTERN int SWIG_Lua_module_get(lua_State* L)
lua_tostring(L,2)); lua_tostring(L,2));
*/ */
/* get the metatable */ /* get the metatable */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
assert(lua_istable(L,1)); /* just in case */ assert(lua_istable(L,1)); /* just in case */
#else
assert(lua_isrotable(L,1));
#endif
lua_getmetatable(L,1); /* get the metatable */ lua_getmetatable(L,1); /* get the metatable */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
assert(lua_istable(L,-1)); /* just in case */ assert(lua_istable(L,-1)); /* just in case */
#else
assert(lua_isrotable(L,-1));
#endif
SWIG_Lua_get_table(L,".get"); /* get the .get table */ SWIG_Lua_get_table(L,".get"); /* get the .get table */
lua_remove(L,3); /* remove metatable */ lua_remove(L,3); /* remove metatable */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
if (lua_istable(L,-1)) if (lua_istable(L,-1))
#else
if (lua_isrotable(L,-1))
#endif
{ {
/* look for the key in the .get table */ /* look for the key in the .get table */
lua_pushvalue(L,2); /* key */ lua_pushvalue(L,2); /* key */
@ -201,7 +213,7 @@ SWIGINTERN int SWIG_Lua_module_get(lua_State* L)
} }
lua_pop(L,1); /* remove the .get */ lua_pop(L,1); /* remove the .get */
lua_pushnil(L); /* return a nil */ lua_pushnil(L); /* return a nil */
return 1; return 1;
} }
/* the module.set method used for setting linked data */ /* the module.set method used for setting linked data */
@ -213,12 +225,24 @@ SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
(3) any for the new value (3) any for the new value
*/ */
/* get the metatable */ /* get the metatable */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
assert(lua_istable(L,1)); /* just in case */ assert(lua_istable(L,1)); /* just in case */
#else
assert(lua_isrotable(L,1));
#endif
lua_getmetatable(L,1); /* get the metatable */ lua_getmetatable(L,1); /* get the metatable */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
assert(lua_istable(L,-1)); /* just in case */ assert(lua_istable(L,-1)); /* just in case */
#else
assert(lua_isrotable(L,-1));
#endif
SWIG_Lua_get_table(L,".set"); /* get the .set table */ SWIG_Lua_get_table(L,".set"); /* get the .set table */
lua_remove(L,4); /* remove metatable */ lua_remove(L,4); /* remove metatable */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
if (lua_istable(L,-1)) if (lua_istable(L,-1))
#else
if (lua_isrotable(L,-1))
#endif
{ {
/* look for the key in the .set table */ /* look for the key in the .set table */
lua_pushvalue(L,2); /* key */ lua_pushvalue(L,2); /* key */
@ -230,6 +254,11 @@ SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
lua_call(L,1,0); lua_call(L,1,0);
return 0; return 0;
} }
#if (SWIG_LUA_TARGET == SWIG_LUA_ELUA)
else {
return 0; // Exits stoically if an invalid key is initialized.
}
#endif
} }
lua_settop(L,3); /* reset back to start */ lua_settop(L,3); /* reset back to start */
/* we now have the table, key & new value, so just set directly */ /* we now have the table, key & new value, so just set directly */
@ -237,6 +266,7 @@ SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
return 0; return 0;
} }
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
/* registering a module in lua. Pushes the module table on the stack. */ /* registering a module in lua. Pushes the module table on the stack. */
SWIGINTERN void SWIG_Lua_module_begin(lua_State* L,const char* name) SWIGINTERN void SWIG_Lua_module_begin(lua_State* L,const char* name)
{ {
@ -291,6 +321,7 @@ SWIGINTERN void SWIG_Lua_module_add_variable(lua_State* L,const char* name,lua_C
} }
lua_pop(L,1); /* tidy stack (remove meta) */ lua_pop(L,1); /* tidy stack (remove meta) */
} }
#endif
/* adding a function module */ /* adding a function module */
SWIGINTERN void SWIG_Lua_module_add_function(lua_State* L,const char* name,lua_CFunction fn) SWIGINTERN void SWIG_Lua_module_add_function(lua_State* L,const char* name,lua_CFunction fn)
@ -705,6 +736,7 @@ SWIGRUNTIME int SWIG_Lua_equal(lua_State* L)
* global variable support code: class/struct typemap functions * global variable support code: class/struct typemap functions
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
/* Install Constants */ /* Install Constants */
SWIGINTERN void SWIGINTERN void
SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) { SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) {
@ -746,6 +778,7 @@ SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) {
} }
} }
} }
#endif
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* executing lua code from within the wrapper * executing lua code from within the wrapper

View file

@ -21,14 +21,22 @@ extern "C" {
added at the very end of the code added at the very end of the code
the function is always called SWIG_init, but an eariler #define will rename it the function is always called SWIG_init, but an eariler #define will rename it
*/ */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
SWIGEXPORT int SWIG_init(lua_State* L) SWIGEXPORT int SWIG_init(lua_State* L)
#else
LUALIB_API int SWIG_init(lua_State* L)
#endif
{ {
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA) || (SWIG_LUA_TARGET == SWIG_LUA_ELUA)
int i; int i;
/* start with global table */ /* start with global table */
lua_pushvalue(L,LUA_GLOBALSINDEX); lua_pushvalue(L,LUA_GLOBALSINDEX);
/* SWIG's internal initalisation */ /* SWIG's internal initalisation */
SWIG_InitializeModule((void*)L); SWIG_InitializeModule((void*)L);
SWIG_PropagateClientData(); SWIG_PropagateClientData();
#endif
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
/* add a global fn */ /* add a global fn */
SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type); SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type);
SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal); SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal);
@ -42,6 +50,9 @@ SWIGEXPORT int SWIG_init(lua_State* L)
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);
} }
#endif
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA) || (SWIG_LUA_TARGET == SWIG_LUA_ELUA)
/* set up base class pointers (the hierachy) */ /* set up base class pointers (the hierachy) */
for (i = 0; swig_types[i]; i++){ for (i = 0; swig_types[i]; i++){
if (swig_types[i]->clientdata){ if (swig_types[i]->clientdata){
@ -54,8 +65,14 @@ SWIGEXPORT int SWIG_init(lua_State* L)
SWIG_Lua_class_register(L,(swig_lua_class*)(swig_types[i]->clientdata)); SWIG_Lua_class_register(L,(swig_lua_class*)(swig_types[i]->clientdata));
} }
} }
#endif
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
/* constants */ /* constants */
SWIG_Lua_InstallConstants(L,swig_constants); SWIG_Lua_InstallConstants(L,swig_constants);
#endif
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA) || (SWIG_LUA_TARGET == SWIG_LUA_ELUA)
/* invoke user-specific initialization */ /* invoke user-specific initialization */
SWIG_init_user(L); SWIG_init_user(L);
/* end module */ /* end module */
@ -63,6 +80,9 @@ SWIGEXPORT int SWIG_init(lua_State* L)
point, we have the globals table and out module table on the stack. Returning point, we have the globals table and out module table on the stack. Returning
one value makes the module table the result of the require command. */ one value makes the module table the result of the require command. */
return 1; return 1;
#else
return 0;
#endif
} }
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -40,8 +40,8 @@
* ver009 * ver009
class support: ok for basic types, but methods still TDB class support: ok for basic types, but methods still TDB
(code is VERY messed up & needs to be cleaned) (code is VERY messed up & needs to be cleaned)
* ver010
Added support for embedded Lua. Try swig -lua -help for more information
*/ */
char cvsroot_lua_cxx[] = "$Id$"; char cvsroot_lua_cxx[] = "$Id$";
@ -83,11 +83,15 @@ void display_mapping(DOH *d) {
NEW LANGUAGE NOTE:END ************************************************/ NEW LANGUAGE NOTE:END ************************************************/
static const char *usage = (char *) "\ static const char *usage = (char *) "\
Lua Options (available with -lua)\n\ Lua Options (available with -lua)\n\
-elua - Generates LTR compatible wrappers for smaller devices running elua\n\
-eluac - LTR compatible wrappers in \"crass compress\" mode for elua\n\
-nomoduleglobal - Do not register the module name as a global variable \n\ -nomoduleglobal - Do not register the module name as a global variable \n\
but return the module table from calls to require.\n\ but return the module table from calls to require.\n\
\n"; \n";
static int nomoduleglobal = 0; static int nomoduleglobal = 0;
static int elua_ltr = 0;
static int eluac_ltr = 0;
/* NEW LANGUAGE NOTE:*********************************************** /* NEW LANGUAGE NOTE:***********************************************
To add a new language, you need to derive your class from To add a new language, you need to derive your class from
@ -111,6 +115,9 @@ private:
String *s_methods_tab; // table of class methods String *s_methods_tab; // table of class methods
String *s_attr_tab; // table of class atributes String *s_attr_tab; // table of class atributes
String *s_luacode; // luacode to be called during init String *s_luacode; // luacode to be called during init
String *s_dot_get; // table of variable 'get' functions
String *s_dot_set; // table of variable 'set' functions
String *s_vars_meta_tab; // metatable for variables
int have_constructor; int have_constructor;
int have_destructor; int have_destructor;
@ -176,6 +183,12 @@ public:
} else if (strcmp(argv[i], "-nomoduleglobal") == 0) { } else if (strcmp(argv[i], "-nomoduleglobal") == 0) {
nomoduleglobal = 1; nomoduleglobal = 1;
Swig_mark_arg(i); Swig_mark_arg(i);
} else if(strcmp(argv[i], "-elua") == 0) {
elua_ltr = 1;
Swig_mark_arg(i);
} else if(strcmp(argv[i], "-eluac") == 0) {
eluac_ltr = 1;
Swig_mark_arg(i);
} }
} }
} }
@ -255,6 +268,10 @@ public:
s_var_tab = NewString(""); s_var_tab = NewString("");
// s_methods_tab = NewString(""); // s_methods_tab = NewString("");
s_const_tab = NewString(""); s_const_tab = NewString("");
s_dot_get = NewString("");
s_dot_set = NewString("");
s_vars_meta_tab = NewString("");
s_luacode = NewString(""); s_luacode = NewString("");
Swig_register_filebyname("luacode", s_luacode); Swig_register_filebyname("luacode", s_luacode);
@ -267,6 +284,13 @@ public:
Printf(f_runtime, "\n"); Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGLUA\n"); Printf(f_runtime, "#define SWIGLUA\n");
if (elua_ltr)
Printf(f_runtime, "#define SWIG_LUA_TARGET SWIG_LUA_ELUA\n");
else if (eluac_ltr)
Printf(f_runtime, "#define SWIG_LUA_TARGET SWIG_LUA_ELUAC\n");
else
Printf(f_runtime, "#define SWIG_LUA_TARGET SWIG_LUA_LUA\n");
if (nomoduleglobal) { if (nomoduleglobal) {
Printf(f_runtime, "#define SWIG_LUA_NO_MODULE_GLOBAL\n"); Printf(f_runtime, "#define SWIG_LUA_NO_MODULE_GLOBAL\n");
} else { } else {
@ -287,12 +311,31 @@ public:
Printf(f_header, "#define SWIG_name \"%s\"\n", module); Printf(f_header, "#define SWIG_name \"%s\"\n", module);
Printf(f_header, "#define SWIG_init luaopen_%s\n", module); Printf(f_header, "#define SWIG_init luaopen_%s\n", module);
Printf(f_header, "#define SWIG_init_user luaopen_%s_user\n\n", module); Printf(f_header, "#define SWIG_init_user luaopen_%s_user\n\n", module);
Printf(f_header, "#define SWIG_LUACODE luaopen_%s_luacode\n\n", module); Printf(f_header, "#define SWIG_LUACODE luaopen_%s_luacode\n", module);
Printf(s_cmd_tab, "\nstatic const struct luaL_reg swig_commands[] = {\n"); if (elua_ltr || eluac_ltr)
Printf(s_var_tab, "\nstatic swig_lua_var_info swig_variables[] = {\n"); Printf(f_header, "#define swig_commands %s_map\n\n", module);
Printf(s_const_tab, "\nstatic swig_lua_const_info swig_constants[] = {\n");
Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); if (elua_ltr || eluac_ltr) {
Printf(s_cmd_tab, "\n#define MIN_OPT_LEVEL 2\n#include \"lrodefs.h\"\n");
Printf(s_cmd_tab, "#include \"lrotable.h\"\n");
Printf(s_cmd_tab, "\nconst LUA_REG_TYPE swig_constants[];\n");
if (elua_ltr)
Printf(s_cmd_tab, "const LUA_REG_TYPE mt[];\n");
Printf(s_cmd_tab, "\nconst LUA_REG_TYPE swig_commands[] = {\n");
Printf(s_const_tab, "\nconst LUA_REG_TYPE swig_constants[] = {\n");
Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
if (elua_ltr) {
Printf(s_dot_get, "\nconst LUA_REG_TYPE dot_get[] = {\n");
Printf(s_dot_set, "\nconst LUA_REG_TYPE dot_set[] = {\n");
}
} else {
Printf(s_cmd_tab, "\nstatic const struct luaL_reg swig_commands[] = {\n");
Printf(s_var_tab, "\nstatic swig_lua_var_info swig_variables[] = {\n");
Printf(s_const_tab, "\nstatic swig_lua_const_info swig_constants[] = {\n");
Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
}
/* %init code inclusion, effectively in the SWIG_init function */ /* %init code inclusion, effectively in the SWIG_init function */
Printf(f_init, "void SWIG_init_user(lua_State* L)\n{\n"); Printf(f_init, "void SWIG_init_user(lua_State* L)\n{\n");
@ -303,11 +346,39 @@ public:
Printf(f_wrappers, "#ifdef __cplusplus\n}\n#endif\n"); Printf(f_wrappers, "#ifdef __cplusplus\n}\n#endif\n");
// Done. Close up the module & write to the wrappers // Done. Close up the module & write to the wrappers
Printv(s_cmd_tab, tab4, "{0,0}\n", "};\n", NIL); if (elua_ltr || eluac_ltr) {
Printv(s_var_tab, tab4, "{0,0,0}\n", "};\n", NIL); Printv(s_cmd_tab, tab4, "{LSTRKEY(\"const\"), LROVAL(swig_constants)},\n", NIL);
Printv(s_const_tab, tab4, "{0,0,0,0,0,0}\n", "};\n", NIL); if (elua_ltr)
Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab, NIL); Printv(s_cmd_tab, tab4, "{LSTRKEY(\"__metatable\"), LROVAL(mt)},\n", NIL);
SwigType_emit_type_table(f_runtime, f_wrappers); Printv(s_cmd_tab, tab4, "{LNILKEY, LNILVAL}\n", "};\n", NIL);
Printv(s_const_tab, tab4, "{LNILKEY, LNILVAL}\n", "};\n", NIL);
} else {
Printv(s_cmd_tab, tab4, "{0,0}\n", "};\n", NIL);
Printv(s_var_tab, tab4, "{0,0,0}\n", "};\n", NIL);
Printv(s_const_tab, tab4, "{0,0,0,0,0,0}\n", "};\n", NIL);
}
if (elua_ltr) {
/* Generate the metatable */
Printf(s_vars_meta_tab, "\nconst LUA_REG_TYPE mt[] = {\n");
Printv(s_vars_meta_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_module_get)},\n", NIL);
Printv(s_vars_meta_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_module_set)},\n", NIL);
Printv(s_vars_meta_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(dot_get)},\n", NIL);
Printv(s_vars_meta_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(dot_set)},\n", NIL);
Printv(s_vars_meta_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL);
Printv(s_dot_get, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL);
Printv(s_dot_set, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL);
}
if (elua_ltr || eluac_ltr) {
/* Final close up of wrappers */
Printv(f_wrappers, s_cmd_tab, s_dot_get, s_dot_set, s_vars_meta_tab, s_var_tab, s_const_tab, NIL);
SwigType_emit_type_table(f_runtime, f_wrappers);
} else {
Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab, NIL);
SwigType_emit_type_table(f_runtime, f_wrappers);
}
/* NEW LANGUAGE NOTE:*********************************************** /* NEW LANGUAGE NOTE:***********************************************
this basically combines several of the strings together this basically combines several of the strings together
@ -333,6 +404,9 @@ public:
Close(f_begin); Close(f_begin);
Delete(f_runtime); Delete(f_runtime);
Delete(f_begin); Delete(f_begin);
Delete(s_dot_get);
Delete(s_dot_set);
Delete(s_vars_meta_tab);
/* Done */ /* Done */
return SWIG_OK; return SWIG_OK;
@ -661,9 +735,13 @@ public:
/* Now register the function with the interpreter. */ /* Now register the function with the interpreter. */
if (!Getattr(n, "sym:overloaded")) { if (!Getattr(n, "sym:overloaded")) {
// add_method(n, iname, wname, description); // add_method(n, iname, wname, description);
if (current==NO_CPP || current==STATIC_FUNC) // emit normal fns & static fns if (current==NO_CPP || current==STATIC_FUNC) { // emit normal fns & static fns
Printv(s_cmd_tab, tab4, "{ \"", iname, "\", ", Swig_name_wrapper(iname), "},\n", NIL); if(elua_ltr || eluac_ltr)
Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", Swig_name_wrapper(iname), ")", "},\n", NIL);
else
Printv(s_cmd_tab, tab4, "{ \"", iname, "\", ", Swig_name_wrapper(iname), "},\n", NIL);
// Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", Swig_name_wrapper(iname), "},\n", NIL); // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", Swig_name_wrapper(iname), "},\n", NIL);
}
} else { } else {
if (!Getattr(n, "sym:nextSibling")) { if (!Getattr(n, "sym:nextSibling")) {
dispatchFunction(n); dispatchFunction(n);
@ -787,8 +865,17 @@ public:
setName = NewString("SWIG_Lua_set_immutable"); // error message setName = NewString("SWIG_Lua_set_immutable"); // error message
//setName = NewString("0"); //setName = NewString("0");
} }
// register the variable // register the variable
Printf(s_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, iname, getName, setName); if (elua_ltr) {
Printf(s_dot_get, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, iname, getName);
Printf(s_dot_set, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, iname, setName);
} else if (eluac_ltr) {
Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", iname, "_get", "\")", ", LFUNCVAL(", getName, ")", "},\n", NIL);
Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", iname, "_set", "\")", ", LFUNCVAL(", setName, ")", "},\n", NIL);
} else {
Printf(s_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, iname, getName, setName);
}
Delete(getName); Delete(getName);
Delete(setName); Delete(setName);
return result; return result;
@ -822,7 +909,7 @@ public:
Replaceall(tm, "$target", name); Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value); Replaceall(tm, "$value", value);
Replaceall(tm, "$nsname", nsname); Replaceall(tm, "$nsname", nsname);
Printf(s_const_tab, "%s,\n", tm); Printf(s_const_tab, " %s,\n", tm);
} else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { } else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
Replaceall(tm, "$source", value); Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name); Replaceall(tm, "$target", name);
@ -1006,7 +1093,17 @@ public:
Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_classname, " = { \"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_classname, " = { \"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL);
if (have_constructor) { if (have_constructor) {
Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name))); if (elua_ltr) {
Printf(s_cmd_tab, " {LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", class_name, \
Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name)));
Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name)));
} else if (eluac_ltr) {
Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", "new_", class_name, "\")", ", LFUNCVAL(", \
Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name)), ")", "},\n", NIL);
Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name)));
} else {
Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name)));
}
Delete(constructor_name); Delete(constructor_name);
constructor_name = 0; constructor_name = 0;
} else { } else {
@ -1014,7 +1111,12 @@ public:
} }
if (have_destructor) { if (have_destructor) {
Printv(f_wrappers, ", swig_delete_", class_name, NIL); if (eluac_ltr) {
Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", "free_", class_name, "\")", ", LFUNCVAL(", "swig_delete_", class_name, ")", "},\n", NIL);
Printv(f_wrappers, ", swig_delete_", class_name, NIL);
} else {
Printv(f_wrappers, ", swig_delete_", class_name, NIL);
}
} else { } else {
Printf(f_wrappers, ",0"); Printf(f_wrappers, ",0");
} }
@ -1080,6 +1182,12 @@ public:
sname = NewString("SWIG_Lua_set_immutable"); // error message sname = NewString("SWIG_Lua_set_immutable"); // error message
} }
Printf(s_attr_tab,"%s{ \"%s\", %s, %s},\n",tab4,symname,gname,sname); Printf(s_attr_tab,"%s{ \"%s\", %s, %s},\n",tab4,symname,gname,sname);
if (eluac_ltr) {
Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", class_name, "_", symname, "_get", "\")", \
", LFUNCVAL(", gname, ")", "},\n", NIL);
Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", class_name, "_", symname, "_set", "\")", \
", LFUNCVAL(", sname, ")", "},\n", NIL);
}
Delete(gname); Delete(gname);
Delete(sname); Delete(sname);
return SWIG_OK; return SWIG_OK;
@ -1160,9 +1268,7 @@ public:
*/ */
String *runtimeCode() { String *runtimeCode() {
String *s = NewString(""); String *s = NewString("");
const char *filenames[] = { "luarun.swg", 0 const char *filenames[] = { "luarun.swg", 0 } ; // must be 0 terminated
}
; // must be 0 termiated
String *sfile; String *sfile;
for (int i = 0; filenames[i] != 0; i++) { for (int i = 0; filenames[i] != 0; i++) {
sfile = Swig_include_sys(filenames[i]); sfile = Swig_include_sys(filenames[i]);
@ -1173,7 +1279,6 @@ public:
Delete(sfile); Delete(sfile);
} }
} }
return s; return s;
} }