MCPcopy Create free account
hub / github.com/defold/defold / TimerDelay

Function TimerDelay

engine/script/src/script_timer.cpp:618–642  ·  view source on GitHub ↗

create a timer * Adds a timer and returns a unique handle. * * You may create more timers from inside a timer callback. * * Using a delay of 0 will result in a timer that triggers at the next frame just before * script update functions. * * If you want a timer that triggers on each frame, set delay to 0.0f and repeat to true. * * Timers created wit

Source from the content-addressed store, hash-verified

616 *
617 */
618 static int TimerDelay(lua_State* L) {
619 int top = lua_gettop(L);
620 luaL_checktype(L, 1, LUA_TNUMBER);
621 luaL_checktype(L, 2, LUA_TBOOLEAN);
622 luaL_checktype(L, 3, LUA_TFUNCTION);
623
624 const double seconds = lua_tonumber(L, 1);
625 if (seconds < 0.0)
626 {
627 return luaL_error(L, "timer.delay does not support negative delay times");
628 }
629
630 bool repeat = lua_toboolean(L, 2);
631 dmScript::HTimerWorld timer_world = CheckTimerWorld(L);
632
633 uintptr_t owner = dmScript::GetInstanceId(L);
634
635 LuaCallbackInfo* user_data = dmScript::CreateCallback(L, 3);
636
637 dmScript::HTimer handle = dmScript::AddTimer(timer_world, seconds, repeat, LuaTimerCallback, (uintptr_t)owner, (uintptr_t)user_data);
638
639 lua_pushinteger(L, handle);
640 assert(top + 1 == lua_gettop(L));
641 return 1;
642 }
643
644 /*# cancel a timer
645 *

Callers

nothing calls this directly

Calls 11

lua_gettopFunction · 0.85
luaL_checktypeFunction · 0.85
lua_tonumberFunction · 0.85
luaL_errorFunction · 0.85
lua_tobooleanFunction · 0.85
CheckTimerWorldFunction · 0.85
GetInstanceIdFunction · 0.85
CreateCallbackFunction · 0.85
AddTimerFunction · 0.85
lua_pushintegerFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected