File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -126,8 +126,8 @@ static int lltimers_on(lua_State *L)
126126 luaL_typeerror (L, 3 , " function or callable table" );
127127 lua_settop (L, 3 );
128128
129- if (seconds < 0.0 )
130- luaL_errorL (L, " timer interval must be positive or 0" );
129+ if (seconds < 0.0 || std::isnan (seconds) )
130+ luaL_errorL (L, " timer interval must be a positive number or 0" );
131131
132132 // Get current time
133133 double current_time = sl_state->clockProvider ? sl_state->clockProvider (L) : 0.0 ;
@@ -182,8 +182,8 @@ static int lltimers_once(lua_State *L)
182182 luaL_typeerror (L, 3 , " function or callable table" );
183183 lua_settop (L, 3 );
184184
185- if (seconds < 0.0 )
186- luaL_errorL (L, " timer interval must be positive or 0" );
185+ if (seconds < 0.0 || std::isnan (seconds) )
186+ luaL_errorL (L, " timer interval must be a positive number or 0" );
187187
188188 // Get current time
189189 double current_time = sl_state->clockProvider ? sl_state->clockProvider (L) : 0.0 ;
Original file line number Diff line number Diff line change @@ -135,6 +135,10 @@ local success, err = pcall(function()
135135end )
136136assert (success == false )
137137
138+ -- Test NaN interval
139+ assert_errors (function () LLTimers :every (0 / 0 , function () end ) end , " timer interval must be a positive number or 0" )
140+ assert_errors (function () LLTimers :once (0 / 0 , function () end ) end , " timer interval must be a positive number or 0" )
141+
138142-- Test zero interval (0 means "ASAP" and is valid)
139143timer1_count = 0
140144local function zero_interval_handler ()
You can’t perform that action at this time.
0 commit comments