- [NEW] sys.chrono()

This commit is contained in:
2026-02-18 10:53:31 +01:00
parent 7c3b58c5f0
commit 9581ce67fd
2 changed files with 19 additions and 0 deletions

12
lua.cpp
View File

@@ -699,6 +699,17 @@ extern "C" {
return 1;
}
static uint32_t chrono_time = 0;
static int cpp_sys_chrono(lua_State *L) {
if (lua_gettop(L) == 0) {
lua_pushnumber(L, float(SDL_GetTicks()-chrono_time)/1000.0f);
return 1;
} else {
chrono_time = SDL_GetTicks();
return 0;
}
}
static int cpp_sys_beat(lua_State *L) {
if (lua_gettop(L) == 0) {
lua_pushboolean(L, beat(-1));
@@ -1049,6 +1060,7 @@ void push_lua_funcs() {
lua_newtable(L);
lua_pushcfunction(L,cpp_sys_delta); lua_setfield(L, -2, "delta");
lua_pushcfunction(L,cpp_sys_time); lua_setfield(L, -2, "time");
lua_pushcfunction(L,cpp_sys_chrono); lua_setfield(L, -2, "chrono");
lua_pushcfunction(L,cpp_sys_beat); lua_setfield(L, -2, "beat");
lua_pushcfunction(L,cpp_sys_update); lua_setfield(L, -2, "update");
lua_pushcfunction(L,cpp_sys_dir); lua_setfield(L, -2, "dir");

View File

@@ -404,6 +404,13 @@ function sys.delta() end
---Get current system timer in seconds (with decimals)
function sys.time() end
---@param offset number
---Reset chrono time (with offset in seconds) (with decimals)
function sys.chrono(offset) end
---Get chrono time since last chrono reset in seconds (with decimals)
function sys.chrono() end
---@return boolean
---Query if a beat has already passed
function sys.beat() end