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
| 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 | * |
nothing calls this directly
no test coverage detected