[aquaria] Patch to run Lua scripts as threads

Alec Holowka zaphire at gmail.com
Tue Jun 29 01:45:43 EDT 2010


So, one way to change the scripts to use local variables... Based on what a
friend told me, and the engine he's working on...

Instead of creating a lua_State for each script, we create a table. Then any
script can access it's table... something like

v = getVars();

then any local variable just has to have "v." added before it.

This doesn't sound like a super hard change to make, although it would
involve changing all the scripts.

On Thu, Jun 17, 2010 at 11:05 AM, Andrew Church
<achurch+aquaria at achurch.org<achurch%2Baquaria at achurch.org>
> wrote:

> I've put together a patch that allows the game's Lua scripts to run as
> threads within a single Lua state.  The patch is admittedly a bit
> hackish, in that it creates a nested environment for each thread so the
> global variables defined in each script don't interfere with those used
> by other scripts, but IMHO the memory savings -- typically around 80% of
> Lua's current memory usage, for example ~16MB in Home Waters -- make it
> worth the change.  The nested environment hack could of course be
> removed in the future if the scripts are updated to use local variables.
> I haven't tested the patch extensively, but in theory it should be safe,
> as the only effective change is merging the common function set into a
> single read-only parent environment.
>
> The patch is attached below, as a compressed file due to its length.
> (Ryan, I hope that's not a problem for either you or the mailing list
> software!)  The actual changes aren't too major; the bulk of the patch
> is due to s/*L/baseState/ in ScriptInterface::createBaseLuaVM()
> (formerly initLuaVM(), which is now used only for threads).
>
> The patch is also in my repository (http://achurch.org/cgi-bin/hg/aquaria/
> )
> on branch "single-lua-state".  It's actually committed as two patches
> there, since part of the change is identical to one of my PSP patches,
> but I've merged them here for (what I hope is) convenience.
>
>  --Andrew Church
>    achurch at achurch.org
>    http://achurch.org/
>
> _______________________________________________
> aquaria mailing list
> aquaria at icculus.org
> http://icculus.org/mailman/listinfo/aquaria
>



-- 
Alec Holowka
www.infiniteammo.ca
www.bit-blot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://icculus.org/pipermail/aquaria/attachments/20100629/e0d48d8a/attachment.htm>


More information about the aquaria mailing list