So, one way to change the scripts to use local variables... Based on what a friend told me, and the engine he&#39;s working on...<div><br></div><div>Instead of creating a lua_State for each script, we create a table. Then any script can access it&#39;s table... something like</div>
<div><br></div><div>v = getVars();</div><div><br></div><div>then any local variable just has to have &quot;v.&quot; added before it.</div><div><br></div><div>This doesn&#39;t sound like a super hard change to make, although it would involve changing all the scripts.<br>
<br><div class="gmail_quote">On Thu, Jun 17, 2010 at 11:05 AM, 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;">
I&#39;ve put together a patch that allows the game&#39;s Lua scripts to run as<br>
threads within a single Lua state.  The patch is admittedly a bit<br>
hackish, in that it creates a nested environment for each thread so the<br>
global variables defined in each script don&#39;t interfere with those used<br>
by other scripts, but IMHO the memory savings -- typically around 80% of<br>
Lua&#39;s current memory usage, for example ~16MB in Home Waters -- make it<br>
worth the change.  The nested environment hack could of course be<br>
removed in the future if the scripts are updated to use local variables.<br>
I haven&#39;t tested the patch extensively, but in theory it should be safe,<br>
as the only effective change is merging the common function set into a<br>
single read-only parent environment.<br>
<br>
The patch is attached below, as a compressed file due to its length.<br>
(Ryan, I hope that&#39;s not a problem for either you or the mailing list<br>
software!)  The actual changes aren&#39;t too major; the bulk of the patch<br>
is due to s/*L/baseState/ in ScriptInterface::createBaseLuaVM()<br>
(formerly initLuaVM(), which is now used only for threads).<br>
<br>
The patch is also in my repository (<a href="http://achurch.org/cgi-bin/hg/aquaria/" target="_blank">http://achurch.org/cgi-bin/hg/aquaria/</a>)<br>
on branch &quot;single-lua-state&quot;.  It&#39;s actually committed as two patches<br>
there, since part of the change is identical to one of my PSP patches,<br>
but I&#39;ve merged them here for (what I hope is) convenience.<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>
_______________________________________________<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>
</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>
</div>