780
.. method:: run_coroutine(func)
780
.. method:: run_coroutine(func[, when = now])
782
782
Hands a Lua coroutine object over to widelands for execution. The object
783
783
must have been created via :func:`coroutine.create`. The coroutine is
784
784
expected to :func:`coroutine.yield` at regular intervals with the
785
absolute game time on which the function should be awakened again.
785
absolute game time on which the function should be awakened again. You
786
should also have a look at :mod:`core.cr`.
788
:arg func: coroutine object to run
789
:type func: :class:`thread`
790
:arg when: absolute time when this coroutine should run
791
:type when: :class:`integer`
787
793
:returns: :const:`nil`
789
795
static int L_run_coroutine(lua_State * L) {
790
796
int nargs = lua_gettop(L);
797
uint32_t runtime = get_game(L).get_gametime();
792
799
report_error(L, "Too little arguments to run_at");
794
LuaCoroutine * cr = new LuaCoroutine_Impl(luaL_checkthread(L, -1));
801
runtime = luaL_checkuint32(L, 2);
804
LuaCoroutine * cr = new LuaCoroutine_Impl(luaL_checkthread(L, 1));
795
805
Game & game = get_game(L);
797
807
lua_pop(L, 1); // Remove coroutine from stack
800
(new Widelands::Cmd_LuaFunction(game.get_gametime(), cr));
809
game.enqueue_command(new Widelands::Cmd_LuaFunction(runtime, cr));