[aquaria] Patch to run Lua scripts as threads

Andrew Church achurch+aquaria at achurch.org
Tue Jul 6 23:59:51 EDT 2010


Just that it feels really roundabout to me, especially with all the "v."
prefixes added to the variables.  As long as we have to set something,
why not just set it once when the thread is created?  Then you don't have
to worry about updating it later, plus you can use "global" variables in
the scripts without worrying about forgetting a "v." somewhere.

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

>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
>
>--00c09f905f33019b32048ab93b3b
>Content-Type: text/html; charset=ISO-8859-1
>Content-Transfer-Encoding: quoted-printable
>
>What&#39;s wrong with setting a global variable before each script function=
> is called?<br><br><div class=3D"gmail_quote">On Tue, Jul 6, 2010 at 6:41 P=
>M, Andrew Church <span dir=3D"ltr">&lt;<a href=3D"mailto:achurch%2Baquaria@=
>achurch.org">achurch+aquaria at achurch.org</a>&gt;</span> wrote:<br>
><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
>x #ccc solid;padding-left:1ex;">Okay, so I&#39;ve run into a little problem=
> with this. =A0I&#39;m not sure what<br>
>approach your friend took, but what I&#39;ve done so far is put a<br>
>&quot;v =3D getVars()&quot; at the top of each script, and put &quot;v.&quo=
>t; in front of all<br>
>local variables. =A0The problem is that the functions in each script all<br=
>>
>see only a single version of &quot;v&quot;, because the getVars() is only e=
>xecuted<br>
>once per script instance.<br>
><br>
>I guess one way around this would be to add a getVars() call to every<br>
>function, but that feels a bit fragile to me -- too easy to miss one<br>
>somewhere, and you can&#39;t even trace the problem easily because it&#39;l=
>l<br>
>fall back to the global &quot;v&quot; definition (which you need for initia=
>lizing<br>
>stuff at the top of the script).<br>
><br>
>What I did for now was to update &quot;v&quot; with the current instance&#3=
>9;s variable<br>
>table right before each call into Lua, but that feels like a hack to me;<br=
>>
>if we have to mess with the Lua environment from C, we might as well go<br>
>back to the nested environments I was using before, because at least with<b=
>r>
>those you don&#39;t have to to a lua_setglobal() on every Lua function call=
>.<br>
><br>
>I don&#39;t know Lua too well, so maybe I&#39;m missing something obvious -=
>-<br>
>any other suggestions?<br>
><div class=3D"im"><br>
> =A0--Andrew Church<br>
> =A0 =A0<a href=3D"mailto:achurch at achurch.org">achurch at achurch.org</a><br>
> =A0 =A0<a href=3D"http://achurch.org/" target=3D"_blank">http://achurch.or=
>g/</a><br>
><br>
></div><div class=3D"im">&gt;So, one way to change the scripts to use local =
>variables... Based on what a<br>
>&gt;friend told me, and the engine he&#39;s working on...<br>
>&gt;<br>
>&gt;Instead of creating a lua_State for each script, we create a table. The=
>n any<br>
>&gt;script can access it&#39;s table... something like<br>
>&gt;<br>
>&gt;v =3D getVars();<br>
>&gt;<br>
>&gt;then any local variable just has to have &quot;v.&quot; added before it=
>.<br>
>&gt;<br>
>&gt;This doesn&#39;t sound like a super hard change to make, although it wo=
>uld<br>
>&gt;involve changing all the scripts.<br>
></div><div><div></div><div class=3D"h5">___________________________________=
>____________<br>
>aquaria mailing list<br>
><a href=3D"mailto:aquaria at icculus.org">aquaria at icculus.org</a><br>
><a href=3D"http://icculus.org/mailman/listinfo/aquaria" target=3D"_blank">h=
>ttp://icculus.org/mailman/listinfo/aquaria</a><br>
></div></div></blockquote></div><br><br clear=3D"all"><br>-- <br>Alec Holowk=
>a<br><a href=3D"http://www.infiniteammo.ca">www.infiniteammo.ca</a><br><a h=
>ref=3D"http://www.bit-blot.com">www.bit-blot.com</a><br>
>
>--00c09f905f33019b32048ab93b3b--
>
>--===============8316068614339074354==
>Content-Type: text/plain; charset="us-ascii"
>MIME-Version: 1.0
>Content-Transfer-Encoding: 7bit
>Content-Disposition: inline
>
>_______________________________________________
>aquaria mailing list
>aquaria at icculus.org
>http://icculus.org/mailman/listinfo/aquaria
>
>--===============8316068614339074354==--


More information about the aquaria mailing list