int luax_insistlove(lua_State *L, const char *k) { luax_insistglobal(L, "love"); luax_insist(L, -1, k); // The love table should be replaced with the top stack // item. Only the reqested table should remain on the stack. lua_replace(L, -2); return 1; }
int luax_register_module(lua_State *L, const WrappedModule &m) { m.type->init(); // Put a reference to the C++ module in Lua. luax_insistregistry(L, REGISTRY_MODULES); Proxy *p = (Proxy *)lua_newuserdata(L, sizeof(Proxy)); p->object = m.module; p->type = m.type; luaL_newmetatable(L, m.module->getName()); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); lua_pushcfunction(L, w__gc); lua_setfield(L, -2, "__gc"); lua_setmetatable(L, -2); lua_setfield(L, -2, m.name); // _modules[name] = proxy lua_pop(L, 1); // Gets the love table. luax_insistglobal(L, "love"); // Create new table for module. lua_newtable(L); // Register all the functions. if (m.functions != nullptr) luax_setfuncs(L, m.functions); // Register types. if (m.types != nullptr) { for (const lua_CFunction *t = m.types; *t != nullptr; t++) (*t)(L); } lua_pushvalue(L, -1); lua_setfield(L, -3, m.name); // love.graphics = table lua_remove(L, -2); // love // Register module instance Module::registerInstance(m.module); return 1; }
int luax_register_module(lua_State *L, const WrappedModule &m) { // Put a reference to the C++ module in Lua. luax_getregistry(L, REGISTRY_MODULES); Proxy *p = (Proxy *)lua_newuserdata(L, sizeof(Proxy)); p->own = true; p->data = m.module; p->flags = m.flags; luaL_newmetatable(L, m.module->getName()); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); lua_pushcfunction(L, w__gc); lua_setfield(L, -2, "__gc"); lua_setmetatable(L, -2); lua_setfield(L, -2, m.name); // _modules[name] = proxy lua_pop(L, 1); // Gets the love table. luax_insistglobal(L, "love"); // Create new table for module. lua_newtable(L); // Register all the functions. luaL_register(L, 0, m.functions); // Register types. if (m.types != 0) for (const lua_CFunction *t = m.types; *t != 0; t++) (*t)(L); lua_pushvalue(L, -1); lua_setfield(L, -3, m.name); // love.graphics = table lua_remove(L, -2); // love return 1; }
int luax_c_insistglobal(lua_State *L, const char *k) { return luax_insistglobal(L, k); }