Re: Lua vs. multi-threads / events driven based application / async operation
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Lua vs. multi-threads / events driven based application / async operation
- From: Asko Kauppi <askok@...>
- Date: 2009年1月23日 21:51:59 +0200
Ziv Barber kirjoitti 23.1.2009 kello 14:07:
Thanks!
Moving to luaL_openlibs solve the problem and I now understanding
why it's not possible to call it directly.
The only problem left for me:
Let's say that I'm creating a thread that is running a Lua based
script that take a lot of time to run (or even an end-less loop). At
some time (let's say on shutdown) I want to tell the lua engine to
stop. What I need is a function on the Lua engine that can terminate
a current lua script, so another thread (the main thread) can force
terminating a script running on the Lua thread. I can add a special
function that allow the script to check for shutdown (that's what
I'm doing now) but it depending on the script writer to use it, else
the application will not be able to close.
Anything having to do with Lua and OS threads, look at Lanes.
http://luaforge.net/projects/lanes/
http://akauppi.googlepages.com/lanes-2008-manual.html
It's able to run multiple Lua instances multithreaded aside each
other. It also has cancellation.
It shouldn't be a hard task. It can be done by checkig a flag on the
main big loop that executing a Lua script and a special function
that can turn on this flag.
Yeah, sure.
Have a look at the Lanes source if you wish. Any suggestions to make
it simpler are appreciated. (this line is sarcastic... >;)
Taking care of race conditions is not a trivial thing.
-asko
On Fri, Jan 23, 2009 at 1:21 PM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br
> wrote:
> 3: The luaopen_* methods cannot be called directly from C; they
should
> be called as Lua C functions like so:
> lua_pushcfunction(L, luaopen_io);
> lua_pushliteral(L, "io");
> lua_call(L, 1, 0);
> Or, like so:
> lua_cpall(L, luaopen_io, "io");
Or just call luaL_openlibs, editing lualibs in linit.c to suit your
needs.
linit.c is meant to be edited and added to your app.