[aquaria] Patch to run Lua scripts as threads

Alec Holowka zaphire at gmail.com
Tue Jul 6 10:54:29 EDT 2010


What's wrong with setting a global variable before each script function is
called?

On Tue, Jul 6, 2010 at 6:41 PM, Andrew Church
<achurch+aquaria at achurch.org<achurch%2Baquaria at achurch.org>
> wrote:

> 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?
>
>  --Andrew Church
>    achurch at achurch.org
>    http://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.
> _______________________________________________
> aquaria mailing list
> aquaria at icculus.org
> http://icculus.org/mailman/listinfo/aquaria
>



-- 
Alec Holowka
www.infiniteammo.ca
www.bit-blot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://icculus.org/pipermail/aquaria/attachments/20100706/6ded5e41/attachment.htm>


More information about the aquaria mailing list