Updated the Lua wrapper code for modules to account for cases where the module's instance is removed from memory completely and recreated during the program's lifetime.

This commit is contained in:
Alex Szpakowski
2014-07-21 14:52:01 -03:00
parent e87fbdcaaf
commit 014b9a46e5
45 changed files with 432 additions and 316 deletions
+9 -8
View File
@@ -30,41 +30,41 @@ namespace love
namespace timer
{
static Timer *instance = 0;
#define instance() (Module::getInstance<Timer>(Module::M_TIMER))
int w_step(lua_State *)
{
instance->step();
instance()->step();
return 0;
}
int w_getDelta(lua_State *L)
{
lua_pushnumber(L, instance->getDelta());
lua_pushnumber(L, instance()->getDelta());
return 1;
}
int w_getFPS(lua_State *L)
{
lua_pushinteger(L, instance->getFPS());
lua_pushinteger(L, instance()->getFPS());
return 1;
}
int w_getAverageDelta(lua_State *L)
{
lua_pushnumber(L, instance->getAverageDelta());
lua_pushnumber(L, instance()->getAverageDelta());
return 1;
}
int w_sleep(lua_State *L)
{
instance->sleep(luaL_checknumber(L, 1));
instance()->sleep(luaL_checknumber(L, 1));
return 0;
}
int w_getTime(lua_State *L)
{
lua_pushnumber(L, instance->getTime());
lua_pushnumber(L, instance()->getTime());
return 1;
}
@@ -83,7 +83,8 @@ static const luaL_Reg functions[] =
extern "C" int luaopen_love_timer(lua_State *L)
{
if (instance == 0)
Timer *instance = instance();
if (instance == nullptr)
{
luax_catchexcept(L, [&](){ instance = new love::timer::sdl::Timer(); });
}