[aquaria] Patch to run Lua scripts as threads
achurch+aquaria at achurch.org
Tue Jul 6 23:41:03 EDT 2010
Okay, so I've run into a little problem with this. I'm not sure what
approach your friend took, but what I've done so far is put a
"v = getVars()" at the top of each script, and put "v." in front of all
local variables. The problem is that the functions in each script all
see only a single version of "v", because the getVars() is only executed
once per script instance.
I guess one way around this would be to add a getVars() call to every
function, but that feels a bit fragile to me -- too easy to miss one
somewhere, and you can't even trace the problem easily because it'll
fall back to the global "v" definition (which you need for initializing
stuff at the top of the script).
What I did for now was to update "v" with the current instance's variable
table right before each call into Lua, but that feels like a hack to me;
if we have to mess with the Lua environment from C, we might as well go
back to the nested environments I was using before, because at least with
those you don't have to to a lua_setglobal() on every Lua function call.
I don't know Lua too well, so maybe I'm missing something obvious --
any other suggestions?
achurch at achurch.org
>So, one way to change the scripts to use local variables... Based on what a
>friend told me, and the engine he's working on...
>Instead of creating a lua_State for each script, we create a table. Then any
>script can access it's table... something like
>v = getVars();
>then any local variable just has to have "v." added before it.
>This doesn't sound like a super hard change to make, although it would
>involve changing all the scripts.
More information about the aquaria