What'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"><<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;">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>
<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">>So, one way to change the scripts to use local variables... Based on what 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 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>
</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>