TOLUA_API void tolua_module (lua_State* L, const char* name, int hasvar) { if (name) { /* tolua module */ lua_pushstring(L,name); lua_rawget(L,-2); if (!lua_istable(L,-1)) /* check if module already exists */ { lua_pop(L,1); lua_newtable(L); lua_pushstring(L,name); lua_pushvalue(L,-2); lua_rawset(L,-4); /* assing module into module */ } } else tolua_push_globals_table(L); if (hasvar) { if (!tolua_ismodulemetatable(L)) /* check if it already has a module metatable */ { /* create metatable to get/set C/C++ variable */ lua_newtable(L); tolua_moduleevents(L); if (lua_getmetatable(L,-2)) lua_setmetatable(L,-2); /* set old metatable as metatable of metatable */ lua_setmetatable(L,-2); } } lua_pop(L,1); /* pop module */ }
TOLUA_API void tolua_module (lua_State* L, const char* name, int hasvar) { if (name) { /* tolua module */ lua_pushstring(L,name); lua_newtable(L); } else { /* global table */ tolua_push_globals_table(L); } if (hasvar) { /* create metatable to get/set C/C++ variable */ lua_newtable(L); tolua_moduleevents(L); if (lua_getmetatable(L,-2)) lua_setmetatable(L,-2); /* set old metatable as metatable of metatable */ lua_setmetatable(L,-2); } if (name) lua_rawset(L,-3); /* assing module into module */ else lua_pop(L,1); /* pop global table */ }
/* Begin module * It pushes the module (or class) table on the stack */ TOLUA_API void tolua_beginmodule (lua_State* L, const char* name) { if (name) { lua_pushstring(L,name); lua_rawget(L,-2); } else tolua_push_globals_table(L); }