void LuaBeans::registerPointerEvents(lua_State* L, class Events& events) { LUASTACK_SET(L); luaCompat_pushTypeByName(L, module_name, udtag_name); if(events.gettable) { lua_pushcfunction(L, events.gettable); luaCompat_handleGettableEvent(L); } if(events.settable) { lua_pushcfunction(L, events.settable); luaCompat_handleSettableEvent(L); } if(events.noindex) { lua_pushcfunction(L, events.noindex); luaCompat_handleNoIndexEvent(L); } if(events.gc) { lua_pushcfunction(L, events.gc); luaCompat_handleGCEvent(L); } lua_pop(L, 1); LUASTACK_CLEAN(L, 0); }
void tLuaObject::RegisterType(lua_State* L, const char* type_name, const char* pointer_type_name) { LUASTACK_SET(L); luaCompat_moduleCreate(L, MODULENAME); lua_pop(L, 1); // Registers the table type and the pointer type luaCompat_newLuaType(L, MODULENAME, type_name); luaCompat_newLuaType(L, MODULENAME, pointer_type_name); #ifdef LUA5 // Registers the weak table to store the pairs // (pointer, LuaObject) to avoid duplication // of Lua objects. This step must be done // only once luaCompat_moduleGet(L, MODULENAME, INSTANCES_CACHE); if(lua_isnil(L, -1)) { lua_pop(L, 1); // pushes tables lua_newtable(L); // pushes metatable and initializes it lua_newtable(L); lua_pushstring(L, "__mode"); lua_pushstring(L, "v"); lua_settable(L, -3); lua_setmetatable(L, -2); // stores in the registry luaCompat_moduleSet(L, MODULENAME, INSTANCES_CACHE); } else lua_pop(L, 1); #endif luaCompat_pushTypeByName(L, MODULENAME, type_name); lua_pushcfunction(L, tLuaObject::generic_index); luaCompat_handleNoIndexEvent(L); lua_pushcfunction(L, tLuaObject::generic_newindex); luaCompat_handleSettableEvent(L); lua_pop(L, 1); luaCompat_pushTypeByName(L, MODULENAME, pointer_type_name); lua_pushcfunction(L, tLuaObject::garbagecollect); luaCompat_handleGCEvent(L); lua_pop(L, 1); LUASTACK_CLEAN(L, 0); }
void LuaBeans::registerObjectEvents(class Events& events) { LUASTACK_SET(L); luaCompat_pushTypeByName(L, module_name, tag_name); if(events.gettable) { lua_pushcfunction(L, events.gettable); luaCompat_handleGettableEvent(L); } if(events.settable) { lua_pushcfunction(L, events.settable); luaCompat_handleSettableEvent(L); } if(events.noindex) { lua_pushcfunction(L, events.noindex); luaCompat_handleNoIndexEvent(L); } if(events.call) { lua_pushcfunction(L, events.call); luaCompat_handleFuncCallEvent(L); } if(events.gc) { lua_pushcfunction(L, events.gc); luaCompat_handleGCEvent(L); } lua_pop(L, 1); LUASTACK_CLEAN(L, 0); }