I suppose I don&#39;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">&lt;<a href="mailto:achurch%2Baquaria@achurch.org">achurch+aquaria@achurch.org</a>&gt;</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 &quot;v.&quot;<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&#39;t have<br>
to worry about updating it later, plus you can use &quot;global&quot; variables in<br>
the scripts without worrying about forgetting a &quot;v.&quot; 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">&gt;What&#39;s wrong with setting a global variable before each script function is<br>
&gt;called?<br>
&gt;<br>
&gt;On Tue, Jul 6, 2010 at 6:41 PM, Andrew Church<br>
</div>&gt;&lt;<a href="mailto:achurch%2Baquaria@achurch.org">achurch+aquaria@achurch.org</a>&lt;<a href="mailto:achurch%252Baquaria@achurch.org">achurch%2Baquaria@achurch.org</a>&gt;<br>
<div><div></div><div class="h5">&gt;&gt; wrote:<br>
&gt;<br>
&gt;&gt; Okay, so I&#39;ve run into a little problem with this.  I&#39;m not sure what<br>
&gt;&gt; approach your friend took, but what I&#39;ve done so far is put a<br>
&gt;&gt; &quot;v = getVars()&quot; at the top of each script, and put &quot;v.&quot; in front of all<br>
&gt;&gt; local variables.  The problem is that the functions in each script all<br>
&gt;&gt; see only a single version of &quot;v&quot;, because the getVars() is only executed<br>
&gt;&gt; once per script instance.<br>
&gt;&gt;<br>
&gt;&gt; I guess one way around this would be to add a getVars() call to every<br>
&gt;&gt; function, but that feels a bit fragile to me -- too easy to miss one<br>
&gt;&gt; somewhere, and you can&#39;t even trace the problem easily because it&#39;ll<br>
&gt;&gt; fall back to the global &quot;v&quot; definition (which you need for initializing<br>
&gt;&gt; stuff at the top of the script).<br>
&gt;&gt;<br>
&gt;&gt; What I did for now was to update &quot;v&quot; with the current instance&#39;s variable<br>
&gt;&gt; table right before each call into Lua, but that feels like a hack to me;<br>
&gt;&gt; if we have to mess with the Lua environment from C, we might as well go<br>
&gt;&gt; back to the nested environments I was using before, because at least with<br>
&gt;&gt; those you don&#39;t have to to a lua_setglobal() on every Lua function call.<br>
&gt;&gt;<br>
&gt;&gt; I don&#39;t know Lua too well, so maybe I&#39;m missing something obvious --<br>
&gt;&gt; any other suggestions?<br>
&gt;&gt;<br>
&gt;&gt;  --Andrew Church<br>
&gt;&gt;    <a href="mailto:achurch@achurch.org">achurch@achurch.org</a><br>
&gt;&gt;    <a href="http://achurch.org/" target="_blank">http://achurch.org/</a><br>
&gt;&gt;<br>
&gt;&gt; &gt;So, one way to change the scripts to use local variables... Based on what<br>
&gt;&gt; a<br>
&gt;&gt; &gt;friend told me, and the engine he&#39;s working on...<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;Instead of creating a lua_State for each script, we create a table. Then<br>
&gt;&gt; any<br>
&gt;&gt; &gt;script can access it&#39;s table... something like<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;v = getVars();<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;then any local variable just has to have &quot;v.&quot; added before it.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;This doesn&#39;t sound like a super hard change to make, although it would<br>
&gt;&gt; &gt;involve changing all the scripts.<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; aquaria mailing list<br>
&gt;&gt; <a href="mailto:aquaria@icculus.org">aquaria@icculus.org</a><br>
&gt;&gt; <a href="http://icculus.org/mailman/listinfo/aquaria" target="_blank">http://icculus.org/mailman/listinfo/aquaria</a><br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;--<br>
&gt;Alec Holowka<br>
&gt;<a href="http://www.infiniteammo.ca" target="_blank">www.infiniteammo.ca</a><br>
&gt;<a href="http://www.bit-blot.com" target="_blank">www.bit-blot.com</a><br>
&gt;<br>
</div></div>&gt;--00c09f905f33019b32048ab93b3b<br>
<div class="im">&gt;Content-Type: text/html; charset=ISO-8859-1<br>
&gt;Content-Transfer-Encoding: quoted-printable<br>
&gt;<br>
</div>&gt;What&amp;#39;s wrong with setting a global variable before each script function=<br>
&gt; is called?&lt;br&gt;&lt;br&gt;&lt;div class=3D&quot;gmail_quote&quot;&gt;On Tue, Jul 6, 2010 at 6:41 P=<br>
&gt;M, Andrew Church &lt;span dir=3D&quot;ltr&quot;&gt;&amp;lt;&lt;a href=3D&quot;mailto:<a href="mailto:achurch%252Baquaria@">achurch%2Baquaria@</a>=<br>
<div class="im">&gt;<a href="http://achurch.org" target="_blank">achurch.org</a>&quot;&gt;<a href="mailto:achurch%2Baquaria@achurch.org">achurch+aquaria@achurch.org</a>&lt;/a&gt;&amp;gt;&lt;/span&gt; wrote:&lt;br&gt;<br>

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

<div class="im">&gt;ref=3D&quot;<a href="http://www.bit-blot.com" target="_blank">http://www.bit-blot.com</a>&quot;&gt;<a href="http://www.bit-blot.com" target="_blank">www.bit-blot.com</a>&lt;/a&gt;&lt;br&gt;<br>
&gt;<br>
</div>&gt;--00c09f905f33019b32048ab93b3b--<br>
&gt;<br>
&gt;--===============8316068614339074354==<br>
<div class="im">&gt;Content-Type: text/plain; charset=&quot;us-ascii&quot;<br>
&gt;MIME-Version: 1.0<br>
&gt;Content-Transfer-Encoding: 7bit<br>
&gt;Content-Disposition: inline<br>
&gt;<br>
&gt;_______________________________________________<br>
</div><div class="im">&gt;aquaria mailing list<br>
&gt;<a href="mailto:aquaria@icculus.org">aquaria@icculus.org</a><br>
&gt;<a href="http://icculus.org/mailman/listinfo/aquaria" target="_blank">http://icculus.org/mailman/listinfo/aquaria</a><br>
&gt;<br>
</div>&gt;--===============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>