Limit `system.{sleep,wait_event}` to timeouts >= 0 (#1666)

Otherwise we might wait forever by mistake.
This commit is contained in:
Guldoman 2023-11-29 02:07:33 +01:00 committed by takase1121
parent 35ef0a9484
commit 4adfd44d9f
No known key found for this signature in database
GPG Key ID: 60EEFFC68EB3031B
1 changed files with 2 additions and 0 deletions

View File

@ -371,6 +371,7 @@ static int f_wait_event(lua_State *L) {
int nargs = lua_gettop(L);
if (nargs >= 1) {
double n = luaL_checknumber(L, 1);
if (n < 0) n = 0;
lua_pushboolean(L, SDL_WaitEventTimeout(NULL, n * 1000));
} else {
lua_pushboolean(L, SDL_WaitEvent(NULL));
@ -846,6 +847,7 @@ static int f_get_time(lua_State *L) {
static int f_sleep(lua_State *L) {
double n = luaL_checknumber(L, 1);
if (n < 0) n = 0;
SDL_Delay(n * 1000);
return 0;
}