lua-users home
lua-l archive

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


On Fri, 2002-03-15 at 14:26, Gabriel Peyré wrote:
> sorry if this question has already been asked ...
> 
> I am trying to run multiple LUA chunks of code at the same time 
> (to make a kind of codeware with robots scripted in LUA).
> To do that I need to process each LUA code one intruction by one
> instruction (or at least line by line), but I didn't manage to do it.
> I've try using the line hook, but without great success ...
> 
> thanks a lot for your attention.

Yes, I'm also looking for a similar solution.  I want Lua to be able to
rune multiple chunks/states/threads/whatever, but be interuptable (to
give control back to the controlling thread).

For example, one project I'm using that has Lua, there are a constant
stream of network events to respond to (which might include triggering a
Lua script).  However, any of these scripts might perform certain user
tasks (like ask the user for some input) - those scripts need to "pause"
and let the other scripts runs on the incoming data.  Also, there may be
several long-running scripts.  These need to pause after, say, 1000
bytecode executions (or something similar) and return control the
hosting C program, so it can handle the network events/ user input/
etc.  Then, of course, when the main loop is all set, it can inform the
Lua interpreter to "wake-up" all the threads and run them again, until
they use up their time slot/byte-code count, and are paused again.

Basically, I need pre-emptive multitasking in a language, where the
interpeter(s) are running in a single OS thread.

I believe on the Lua site there is a patch to do this - it is rather
buggy, in places, however.  Perhaps someone more experienced with the
Lua internals could fix it up?

> 
> - gabriel -
>