lua-users home
lua-l archive

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



On Tue, Feb 3, 2015 at 11:30 AM, Are Leistad <aleistad@telia.com> wrote:
Milind Gupta wrote:
> I had written a small C module to allow running multiple Lua scripts by
> executing each one for a certain number of steps, also allowing data passing
> from the parent script to the child scripts. But it uses hooks in the C API.
>
> Milind
 
I'm doing something similar, only with a simpler implementation, using lua_newthread() and yielding from the debug hook. It works fine, executing any Lua function as a timesliced thread and allowing multiple such threads to run with the script. There are some snags; the global thread isn't timesliced, and I can't currently actual Lua coroutines don't cooperate fully. The reason I posted about this is that I think it would be nice if Lua supported cooperative timeslicing of the VM in a general and efficient manner.

Yes coroutines was the tricky part but I managed to get them working by wrapping the coroutine functions inside each new thread. Every thread is a new lua state and is 'instruction' sliced controlled by the main lua script that started the thread.  



Denne e-posten er fri for virus og uønsket programvare fordi avast! Antivirus beskyttelsen er aktiv.