lovr/src/api/l_timer.c

55 lines
1.2 KiB
C
Raw Normal View History

2017-12-10 20:40:37 +00:00
#include "api.h"
2016-11-19 09:28:01 +00:00
#include "timer/timer.h"
2021-03-16 00:54:27 +00:00
#include <lua.h>
#include <lauxlib.h>
2016-08-10 06:28:17 +00:00
2018-09-27 01:27:38 +00:00
static int l_lovrTimerGetDelta(lua_State* L) {
2016-11-05 05:29:38 +00:00
lua_pushnumber(L, lovrTimerGetDelta());
return 1;
}
2018-09-27 01:27:38 +00:00
static int l_lovrTimerGetAverageDelta(lua_State* L) {
2017-05-17 02:25:29 +00:00
lua_pushnumber(L, lovrTimerGetAverageDelta());
return 1;
}
2018-09-27 01:27:38 +00:00
static int l_lovrTimerGetFPS(lua_State* L) {
lua_pushinteger(L, lovrTimerGetFPS());
2016-11-27 02:58:58 +00:00
return 1;
}
2018-09-27 01:27:38 +00:00
static int l_lovrTimerGetTime(lua_State* L) {
2016-11-05 05:29:38 +00:00
lua_pushnumber(L, lovrTimerGetTime());
2016-08-10 06:28:17 +00:00
return 1;
}
2018-09-27 01:27:38 +00:00
static int l_lovrTimerStep(lua_State* L) {
2016-08-10 06:28:17 +00:00
lua_pushnumber(L, lovrTimerStep());
return 1;
}
2016-10-01 22:11:33 +00:00
2018-09-27 01:27:38 +00:00
static int l_lovrTimerSleep(lua_State* L) {
2016-10-01 22:11:33 +00:00
double duration = luaL_checknumber(L, 1);
lovrTimerSleep(duration);
return 0;
}
2017-03-11 11:08:07 +00:00
2018-09-27 01:27:38 +00:00
static const luaL_Reg lovrTimer[] = {
2017-03-11 11:08:07 +00:00
{ "getDelta", l_lovrTimerGetDelta },
2017-05-17 02:25:29 +00:00
{ "getAverageDelta", l_lovrTimerGetAverageDelta },
2017-03-11 11:08:07 +00:00
{ "getFPS", l_lovrTimerGetFPS },
{ "getTime", l_lovrTimerGetTime },
{ "step", l_lovrTimerStep },
{ "sleep", l_lovrTimerSleep },
{ NULL, NULL }
};
2018-09-27 01:27:38 +00:00
int luaopen_lovr_timer(lua_State* L) {
2018-09-27 01:27:38 +00:00
lua_newtable(L);
2020-08-19 19:12:06 +00:00
luax_register(L, lovrTimer);
if (lovrTimerInit()) {
luax_atexit(L, lovrTimerDestroy);
}
2018-09-27 01:27:38 +00:00
return 1;
}