lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It looks like the Lua 5.0 coroutine feature is what you need:
Use coroutine.yield to pause execution and coroutine.resume (from c side,
there is some c function too) to go on.
You can take a closer look at it in the manual.

Note that it isn't possible to yield from behind a C function, but this
restriction comes from the fact that you cannot force a C function to return
;-)
You would have the same problem if you tried any other way to get the
function you want.

----- Original Message ----- 
From: "antero" <antero@ngs.ru>
To: <lua@bazar2.conectiva.com.br>
Sent: Friday, August 08, 2003 10:14 AM


> Hello All,
>
> I am using Lua 5.0 and now trying to create Lua command(C-function)
>  that will stop execution of script, but in such a way that I can later
>  resume it.
>
>  I want to make it work in such a way:
>  ---------script.lua---------
>  print "Lua: Before Wait";
>  -- vvvv This is command i'm trying to implement
>  wait(1);
>  print "Lua: After Wait";
>  ----------test.c-----------
>  [...]
>   printf("The Start!\n");
>   lua_dofile(L,"script.lua");
>   printf("Press any key to continue...");
>   getch();
>   lua_resumeafterwait(L);
>   printf("The End!\n");
>  [...]
>  ---Program Output----------
>  The Start!
>  Lua: Before Wait
>  Press any key to continue...
>  Lua: After Wait
>  The End!
>  --------------------------------
>
>  Can it be done? If it can be done, can you give me some advises(how
>  to implement such command)?
>
>  PS Multithreading is not a solution in my case(i have already looked
>  through Titmouse code)
>  PPS Excuse my English...
>
> -- 
> Best regards,
>  Antero Vipunen.
>