Unluckily, Lua can't marshall its data structures between independent
states. If you like Erlang, you don't want global state, but projects
that have tried this before run into difficulty with marshalling
anything other than numbers, strings, and lightuserdata. You might be
able to handle tables, though recursive tables, and objects (aka
tables with metatables) are hard. You can send compiled lua functions,
and I think the debug library can return the source (compiled?) for
some functions, but people have reported problems doing this.
I spent some time last year learning Erlang, and I have to say, I love
the way it works. However, I find the syntax totally unusable for my
everyday use.
I have an idea for Lua after digging through its sources. I love Lua,
it's fast, simple and brain-dead easy to extend.What I would like to
do is add Erlang style co-currency and actor based programming models
to Lua. Basically the idea would be to spawn a separate LuaState for
each "process" (in the Erlang sense of the word). Then in the main
loop of the interpreter, we could exit early after a certain number of
OPS have been executed.
From here we can spawn n+1 OS threads where n is the number of CPUs.
By cycling through the LuaStates we should be able to keep all the
CPUs busy all the time.
My idea is to add these extra LuaStates as "children" of the first
state created. In this way all the existing C modules should/might
continue to work. Granted if two processes call the same thread we may
have issues, but hey, it's not a perfect world.
Throw into this mix a simple ! operator so we can do:
pid ! message
And we would be on the road to having Erlang style co currency in Lua.
Is anyone interested in working on this with me? I know C like the
back of my hand, I could just use some feedback/backup in the codin
--
"One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs."
(Robert Firth)