[aquaria] Patch to run Lua scripts as threads

Andrew Church achurch+aquaria at achurch.org
Tue Jun 29 17:26:16 EDT 2010


>Well even if it's local to the script (not sure that the entire script is
>considered a block or not), that doesn't solve the problem of creating
>multiple instances of one loaded script. (which is what we want, right?)

Hmm, good point.  If you use loadfile() to open the script, it looks
like you get a Lua function back (an anonymous function containing the
script as a block), so each invocation of that function would create new
local variables.  I was thinking you could use that function as the main
function of a Lua thread for each entity, but then I guess you'd need to
add some sort of "while ~dead do waitForEvent() end" loop to every
script and change the entire event processing system to send events to
the script event loop rather than calling Lua functions directly, which
sounds like a pain.  I guess you could load the file and lua_dump() it
into a memory buffer, which would then be faster to load for subsequent
entities because it wouldn't have to be recompiled again -- but that's
probably a worse hack than what I have right now.

I dunno, maybe I'm trying to make the code prettier than it needs to be? (:

  --Andrew Church
    achurch at achurch.org
    http://achurch.org/


More information about the aquaria mailing list