mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-08 23:23:38 +00:00
0e99d47394
There is a problem when a Thread stops: it destroys all of the modules that it required. This is because we unconditionally call luax_atexit when modules are required, and when the thread lua_State dies it takes all of the modules with it. To fix this, lovr<Module>Init will return whether or not initialization successfully happened, which provides us with enough info to know if we should place the luax_atexit destructor
53 lines
1.1 KiB
C
53 lines
1.1 KiB
C
#include "api.h"
|
|
#include "timer/timer.h"
|
|
|
|
static int l_lovrTimerGetDelta(lua_State* L) {
|
|
lua_pushnumber(L, lovrTimerGetDelta());
|
|
return 1;
|
|
}
|
|
|
|
static int l_lovrTimerGetAverageDelta(lua_State* L) {
|
|
lua_pushnumber(L, lovrTimerGetAverageDelta());
|
|
return 1;
|
|
}
|
|
|
|
static int l_lovrTimerGetFPS(lua_State* L) {
|
|
lua_pushnumber(L, lovrTimerGetFPS());
|
|
return 1;
|
|
}
|
|
|
|
static int l_lovrTimerGetTime(lua_State* L) {
|
|
lua_pushnumber(L, lovrTimerGetTime());
|
|
return 1;
|
|
}
|
|
|
|
static int l_lovrTimerStep(lua_State* L) {
|
|
lua_pushnumber(L, lovrTimerStep());
|
|
return 1;
|
|
}
|
|
|
|
static int l_lovrTimerSleep(lua_State* L) {
|
|
double duration = luaL_checknumber(L, 1);
|
|
lovrTimerSleep(duration);
|
|
return 0;
|
|
}
|
|
|
|
static const luaL_Reg lovrTimer[] = {
|
|
{ "getDelta", l_lovrTimerGetDelta },
|
|
{ "getAverageDelta", l_lovrTimerGetAverageDelta },
|
|
{ "getFPS", l_lovrTimerGetFPS },
|
|
{ "getTime", l_lovrTimerGetTime },
|
|
{ "step", l_lovrTimerStep },
|
|
{ "sleep", l_lovrTimerSleep },
|
|
{ NULL, NULL }
|
|
};
|
|
|
|
int luaopen_lovr_timer(lua_State* L) {
|
|
lua_newtable(L);
|
|
luaL_register(L, NULL, lovrTimer);
|
|
if (lovrTimerInit()) {
|
|
luax_atexit(L, lovrTimerDestroy);
|
|
}
|
|
return 1;
|
|
}
|