diff --git a/lua.cpp b/lua.cpp index 5828861..16a3f3a 100644 --- a/lua.cpp +++ b/lua.cpp @@ -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"); diff --git a/vscode/library.lua b/vscode/library.lua index 8fa630c..c124b9f 100644 --- a/vscode/library.lua +++ b/vscode/library.lua @@ -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