What&#39;s wrong with setting a global variable before each script function is called?<br><br><div class="gmail_quote">On Tue, Jul 6, 2010 at 6:41 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;">Okay, so I&#39;ve run into a little problem with this.  I&#39;m not sure what<br>
approach your friend took, but what I&#39;ve done so far is put a<br>
&quot;v = getVars()&quot; at the top of each script, and put &quot;v.&quot; in front of all<br>
local variables.  The problem is that the functions in each script all<br>
see only a single version of &quot;v&quot;, 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&#39;t even trace the problem easily because it&#39;ll<br>
fall back to the global &quot;v&quot; definition (which you need for initializing<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&#39;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&#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="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;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. Then any<br>
&gt;script can access it&#39;s table... something like<br>
&gt;<br>
&gt;v = 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 would<br>
&gt;involve changing all the scripts.<br>
</div><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>