void LuaInterface::pushObject(const LuaObjectPtr& obj) { // fills a new userdata with a new LuaObjectPtr pointer new(newUserdata(sizeof(LuaObjectPtr))) LuaObjectPtr(obj); // set the userdata metatable getGlobal(Fw::mkstr(obj->getClassName(), "_mt")); assert(!isNil()); setMetatable(); }
void LuaInterface::pushObject(const LuaObjectPtr& obj) { // fills a new userdata with a new LuaObjectPtr pointer new(newUserdata(sizeof(LuaObjectPtr))) LuaObjectPtr(obj); m_totalObjRefs++; obj->luaGetMetatable(); if(isNil()) g_logger.fatal(stdext::format("metatable for class '%s' not found, did you bind the C++ class?", obj->getClassName())); setMetatable(); }
void LuaInterface::pushCppFunction(const LuaCppFunction& func) { // create a pointer to func (this pointer will hold the function existence) new(newUserdata(sizeof(LuaCppFunctionPtr))) LuaCppFunctionPtr(new LuaCppFunction(func)); // sets the userdata __gc metamethod, needed to free the function pointer when it gets collected newTable(); pushCFunction(&LuaInterface::luaCollectCppFunction); setField("__gc"); setMetatable(); // actually pushes a C function callback that will call the cpp function pushCFunction(&LuaInterface::luaCppFunctionCallback, 1); }
static int createLuaobj(lua_State* L, IniFile* ini) { return newUserdata(L, ini, INI_META_LIB); }