[aquaria] Patch to run Lua scripts as threads

Andrew Church achurch+aquaria at achurch.org
Mon Jul 5 10:38:23 EDT 2010


>Slightly off topic, but I'm guessing one way to get everything onto one
>state would be to append the name of the script to every common function
>call.
>
>So like nautilusUpdate() or nautilus_update() instead of update()
>
>This seems like it might be a major pain in the ass though?

Yeah, I was thinking about that too but it raises all sorts of problems,
like having to know the script name to call it from C code, having to
rename all the functions if you rename the file, dealing with filename
case issues (since Lua identifiers are case-sensitive)...  Not really
worth it IMHO.

Another thing I was thinking of was setting up something like an
interface table, which you could return at the bottom of each source
file -- at least I assume you can do that because loadfile() treats the
entire source file as a function.  So you'd do like

local interface = {}
function interface.init() ... end
function interface.update() ... end
return interface

Then the C code would save that table, and when it needed to call a
function it would look up the function in there instead of in the global
table.  That would be less invasive, I think; the problem is that it
breaks on dofile() includes -- you can't declare helper functions
globally because of name collisions, and you couldn't make them local
because then they'd be local to the include file instead of the calling
script.  You could maybe treat include files like modules and do
'local doorcommon = dofile("doorcommon")' or some such, then change
all the calls like commonInit() to doorcommon.commonInit(), but again,
I'm not sure it'd be worth going that far.

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


More information about the aquaria mailing list