From 1d528bada66e33587abea9adbd31f2108642e2d0 Mon Sep 17 00:00:00 2001 From: AsynchronousAI Date: Sun, 7 Jan 2024 18:53:24 -0600 Subject: [PATCH] Add `mwait` function --- VM/src/lbaselib.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/VM/src/lbaselib.cpp b/VM/src/lbaselib.cpp index f4dac61f..2aeb5081 100644 --- a/VM/src/lbaselib.cpp +++ b/VM/src/lbaselib.cpp @@ -10,6 +10,11 @@ #include #include #include +#ifdef _WIN32 +#include +#else +#include +#endif static void writestring(const char* s, size_t l) { @@ -32,6 +37,19 @@ static int luaB_print(lua_State* L) return 0; } +static int luaB_mwait(lua_State* L) +{ + int milliseconds = lua_gettop(L); + luaL_checkinteger(L, milliseconds); + #ifdef _WIN32 + Sleep(milliseconds); + #else + usleep(milliseconds * 1000); + #endif + + return 0; +} + static int luaB_tonumber(lua_State* L) { int base = luaL_optinteger(L, 2, 10); @@ -434,6 +452,7 @@ static const luaL_Reg base_funcs[] = { {"next", luaB_next}, {"newproxy", luaB_newproxy}, {"print", luaB_print}, + {"mwait", luaB_mwait}, {"rawequal", luaB_rawequal}, {"rawget", luaB_rawget}, {"rawset", luaB_rawset},