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,30 @@
* 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
* ----------------------------------------------------------------------------- */
@ -18,27 +42,27 @@
* ----------------------------------------------------------------------------- */
// 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
{ SWIG_LUA_INT, (char *)"$symname", (long) $value, 0, 0, 0}
{SWIG_LUA_CONSTTAB_INT("$symname", $value)}
%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
{ 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&
{ SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) *$value, 0, 0}
{SWIG_LUA_CONSTTAB_FLOAT("$symname", *$value)}
%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
// signed char & unsigned char are numbers
%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
{ SWIG_LUA_STRING, (char *) "$symname", 0, 0, (void *)"$value", 0}
{SWIG_LUA_CONSTTAB_STRING("$symname", "$value")}
%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE []
{ 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));
*/
/* get the metatable */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
assert(lua_istable(L,1)); /* just in case */
#else
assert(lua_isrotable(L,1));
#endif
lua_getmetatable(L,1); /* get the metatable */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
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 */
lua_remove(L,3); /* remove metatable */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
if (lua_istable(L,-1))
#else
if (lua_isrotable(L,-1))
#endif
{
/* look for the key in the .get table */
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_pushnil(L); /* return a nil */
return 1;
return 1;
}
/* 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
*/
/* get the metatable */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
assert(lua_istable(L,1)); /* just in case */
#else
assert(lua_isrotable(L,1));
#endif
lua_getmetatable(L,1); /* get the metatable */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
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 */
lua_remove(L,4); /* remove metatable */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
if (lua_istable(L,-1))
#else
if (lua_isrotable(L,-1))
#endif
{
/* look for the key in the .set table */
lua_pushvalue(L,2); /* key */
@ -230,6 +254,11 @@ SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
lua_call(L,1,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 */
/* 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;
}
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
/* registering a module in lua. Pushes the module table on the stack. */
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) */
}
#endif
/* adding a function module */
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
* ----------------------------------------------------------------------------- */
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
/* Install Constants */
SWIGINTERN void
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

View file

@ -21,14 +21,22 @@ extern "C" {
added at the very end of the code
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)
#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;
/* start with global table */
lua_pushvalue(L,LUA_GLOBALSINDEX);
/* SWIG's internal initalisation */
SWIG_InitializeModule((void*)L);
SWIG_PropagateClientData();
#endif
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
/* add a global fn */
SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type);
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++){
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) */
for (i = 0; swig_types[i]; i++){
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));
}
}
#endif
#if (SWIG_LUA_TARGET == SWIG_LUA_LUA)
/* 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 */
SWIG_init_user(L);
/* 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
one value makes the module table the result of the require command. */
return 1;
#else
return 0;
#endif
}
#ifdef __cplusplus