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