int luaopen_sdl(lua_State *L) { fps_ctrl* ctrl = (fps_ctrl*)lua_newuserdata(L, sizeof(fps_ctrl)); ctrl->init(); luaT_register(L, "sdl", sdllib); const luaL_Reg *pUpvaluedFunctions = sdllib_with_upvalue; for(; pUpvaluedFunctions->name; ++pUpvaluedFunctions) { lua_pushvalue(L, -2); luaT_pushcclosure(L, pUpvaluedFunctions->func, 1); lua_setfield(L, -2, pUpvaluedFunctions->name); } #define LOAD_EXTRA(name, fn) \ luaT_pushcfunction(L, fn); \ lua_call(L, 0, 1); \ lua_setfield(L, -2, name) LOAD_EXTRA("audio", luaopen_sdl_audio); LOAD_EXTRA("wm", luaopen_sdl_wm); #undef LOAD_EXTRA return 1; }
int luaopen_sdl(lua_State *L) { fps_ctrl* ctrl = (fps_ctrl*)lua_newuserdata(L, sizeof(fps_ctrl)); ctrl->init(); luaT_register(L, "sdl", sdllib); for (auto reg = sdllib_with_upvalue.begin(); reg->name; ++reg) { lua_pushvalue(L, -2); luaT_pushcclosure(L, reg->func, 1); lua_setfield(L, -2, reg->name); } load_extra(L, "audio", luaopen_sdl_audio); load_extra(L, "wm", luaopen_sdl_wm); return 1; }
int luaopen_sdl(lua_State *L) { fps_ctrl* ctrl = (fps_ctrl*)lua_newuserdata(L, sizeof(fps_ctrl)); ctrl->init(); luaT_register(L, "sdl", sdllib); const luaL_Reg *pUpvaluedFunctions = sdllib_with_upvalue; for(; pUpvaluedFunctions->name; ++pUpvaluedFunctions) { lua_pushvalue(L, -2); luaT_pushcclosure(L, pUpvaluedFunctions->func, 1); lua_setfield(L, -2, pUpvaluedFunctions->name); } load_extra(L, "audio", luaopen_sdl_audio); load_extra(L, "wm", luaopen_sdl_wm); return 1; }
int luaopen_sdl_audio(lua_State *L) { lua_newtable(L); luaL_register(L, NULL, sdl_audiolib); lua_pushboolean(L, 1); lua_setfield(L, -2, "loaded"); lua_createtable(L, 0, 2); lua_pushvalue(L, -1); lua_replace(L, luaT_environindex); lua_pushvalue(L, luaT_environindex); lua_pushcclosure(L, luaT_stdgc<music_t, luaT_environindex>, 1); lua_setfield(L, -2, "__gc"); lua_pushvalue(L, 1); lua_setfield(L, -2, "__index"); lua_pop(L, 1); luaT_register(L, NULL, sdl_musiclib); return 1; }