~son-of-yhwh/widelands/experimental

« back to all changes in this revision

Viewing changes to src/scripting/lua_game.cc

  • Committer: Holger Rapp
  • Date: 2010-02-06 23:11:51 UTC
  • mto: (4917.6.11 win-conditions)
  • mto: This revision was merged to the branch mainline in revision 5208.
  • Revision ID: sirver@kallisto.local-20100206231151-vkg4t2vhh600pskx
First version of core scripting. Yet undecided about a few things

Show diffs side-by-side

added added

removed removed

Lines of Context:
777
777
 
778
778
 
779
779
/* RST
780
 
        .. method:: run_coroutine(func)
 
780
        .. method:: run_coroutine(func[, when = now])
781
781
 
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`.
 
787
 
 
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`
786
792
 
787
793
                :returns: :const:`nil`
788
794
*/
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();
791
798
        if (nargs < 1)
792
799
                report_error(L, "Too little arguments to run_at");
793
 
 
794
 
        LuaCoroutine * cr = new LuaCoroutine_Impl(luaL_checkthread(L, -1));
 
800
        if (nargs == 2)
 
801
                runtime = luaL_checkuint32(L, 2);
 
802
 
 
803
 
 
804
        LuaCoroutine * cr = new LuaCoroutine_Impl(luaL_checkthread(L, 1));
795
805
        Game & game = get_game(L);
796
806
 
797
807
        lua_pop(L, 1); // Remove coroutine from stack
798
808
 
799
 
        game.enqueue_command
800
 
                (new Widelands::Cmd_LuaFunction(game.get_gametime(), cr));
 
809
        game.enqueue_command(new Widelands::Cmd_LuaFunction(runtime, cr));
801
810
 
802
811
        return 0;
803
812
}