SF patch #3394339 from Torsten Landschoff - new option -nomoduleglobal to disable installing the module table into the global namespace. Require call also returns the module table instead of a string

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12780 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2011-08-22 19:27:56 +00:00
commit 932f47a845
8 changed files with 87 additions and 11 deletions

View file

@ -237,7 +237,7 @@ SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
return 0;
}
/* registering a module in 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)
{
assert(lua_istable(L,-1)); /* just in case */
@ -254,8 +254,16 @@ SWIGINTERN void SWIG_Lua_module_begin(lua_State* L,const char* name)
lua_newtable(L); /* the .set table */
lua_rawset(L,-3); /* add .set into metatable */
lua_setmetatable(L,-2); /* sets meta table in module */
#ifdef SWIG_LUA_MODULE_GLOBAL
/* If requested, install the module directly into the global namespace. */
lua_rawset(L,-3); /* add module into parent */
SWIG_Lua_get_table(L,name); /* get the table back out */
#else
/* Do not install the module table as global name. The stack top has
the module table with the name below. We pop the top and replace
the name with it. */
lua_replace(L,-2);
#endif
}
/* ending the register */

View file

@ -59,8 +59,9 @@ SWIGEXPORT int SWIG_init(lua_State* L)
/* invoke user-specific initialization */
SWIG_init_user(L);
/* end module */
lua_pop(L,1); /* tidy stack (remove module table)*/
lua_pop(L,1); /* tidy stack (remove global table)*/
/* Note: We do not clean up the stack here (Lua will do this for us). At this
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;
}