File tree Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -122,8 +122,8 @@ static int lltimers_on(lua_State *L)
122122 luaL_typeerror (L, 3 , " function or callable table" );
123123 lua_settop (L, 3 );
124124
125- if (seconds <= 0.0 )
126- luaL_errorL (L, " timer interval must be positive" );
125+ if (seconds < 0.0 )
126+ luaL_errorL (L, " timer interval must be positive or 0 " );
127127
128128 // Get current time
129129 double current_time = sl_state->clockProvider ? sl_state->clockProvider (L) : 0.0 ;
@@ -176,8 +176,8 @@ static int lltimers_once(lua_State *L)
176176 luaL_typeerror (L, 3 , " function or callable table" );
177177 lua_settop (L, 3 );
178178
179- if (seconds <= 0.0 )
180- luaL_errorL (L, " timer interval must be positive" );
179+ if (seconds < 0.0 )
180+ luaL_errorL (L, " timer interval must be positive or 0 " );
181181
182182 // Get current time
183183 double current_time = sl_state->clockProvider ? sl_state->clockProvider (L) : 0.0 ;
Original file line number Diff line number Diff line change @@ -135,11 +135,15 @@ local success, err = pcall(function()
135135end )
136136assert (success == false )
137137
138- -- Test zero interval
139- success , err = pcall (function ()
140- LLTimers :on (0 , function () end )
141- end )
142- assert (success == false )
138+ -- Test zero interval (0 means "ASAP" and is valid)
139+ timer1_count = 0
140+ local function zero_interval_handler ()
141+ timer1_count += 1
142+ end
143+ LLTimers :on (0 , zero_interval_handler )
144+ LLTimers :_tick ()
145+ assert (timer1_count == 1 )
146+ LLTimers :off (zero_interval_handler )
143147
144148-- Test invalid handler type
145149success , err = pcall (function ()
You can’t perform that action at this time.
0 commit comments