Changed love module to init all classes before anything else

This commit is contained in:
rxi
2014-06-14 13:59:56 +01:00
parent be2a788b05
commit cb56dad31b

View File

@@ -16,35 +16,16 @@ int l_love_getVersion(lua_State *L) {
} }
/* Submodules */ int luaopen_image(lua_State *L);
int luaopen_quad(lua_State *L);
int luaopen_font(lua_State *L);
int luaopen_system(lua_State *L); int luaopen_system(lua_State *L);
int luaopen_graphics(lua_State *L); int luaopen_graphics(lua_State *L);
int luaopen_timer(lua_State *L); int luaopen_timer(lua_State *L);
int luaopen_keyboard(lua_State *L); int luaopen_keyboard(lua_State *L);
/* Classes */
int luaopen_image(lua_State *L);
int luaopen_quad(lua_State *L);
int luaopen_font(lua_State *L);
int luaopen_love(lua_State *L) { int luaopen_love(lua_State *L) {
int i; int i;
luaL_Reg reg[] = {
{ "getVerson", l_love_getVersion },
{ 0, 0 },
};
luaL_newlib(L, reg);
/* Init submodules */
struct { char *name; int (*fn)(lua_State *L); } mods[] = {
{ "system", luaopen_system },
{ "graphics", luaopen_graphics },
{ "timer", luaopen_timer },
{ "keyboard", luaopen_keyboard },
{ 0 },
};
for (i = 0; mods[i].name; i++) {
mods[i].fn(L);
lua_setfield(L, -2, mods[i].name);
}
/* Init classes -- all the built in classes are inited here as to create the /* Init classes -- all the built in classes are inited here as to create the
* metatables required by their constructors. Any new classes must also be * metatables required by their constructors. Any new classes must also be
* registered here before they will work. */ * registered here before they will work. */
@@ -58,5 +39,25 @@ int luaopen_love(lua_State *L) {
classes[i](L); classes[i](L);
lua_pop(L, 1); lua_pop(L, 1);
} }
/* Init love module */
luaL_Reg reg[] = {
{ "getVerson", l_love_getVersion },
{ 0, 0 },
};
luaL_newlib(L, reg);
/* Init submodules */
struct { char *name; int (*fn)(lua_State *L); } mods[] = {
{ "system", luaopen_system },
{ "graphics", luaopen_graphics },
{ "timer", luaopen_timer },
{ "keyboard", luaopen_keyboard },
{ 0 },
};
for (i = 0; mods[i].name; i++) {
mods[i].fn(L);
lua_setfield(L, -2, mods[i].name);
}
return 1; return 1;
} }