[aquaria] Patch to run Lua scripts as threads

Alec Holowka zaphire at gmail.com
Tue Jun 29 03:59:09 EDT 2010


Well even if it's local to the script (not sure that the entire script is
considered a block or not), that doesn't solve the problem of creating
multiple instances of one loaded script. (which is what we want, right?)

i.e. right now Aquaria loads the "FlyingPoo" script for however many flying
poos are in the level, so say... 100. that's 100 lua_States, it reads the
file off the disk 100 times, really slow.

We'd rather it loaded the "FlyingPoo" script once and create 100 sets of the
local variables for the separate instances.

I don't think the "local" keyword will do that...

On Tue, Jun 29, 2010 at 11:49 AM, Andrew Church
<achurch+aquaria at achurch.org<achurch%2Baquaria at achurch.org>
> wrote:

> >I don't know that "local" works that way, see:
> >http://www.lua.org/pil/4.2.html
> >
> >I find that page of documentation kind of confusing. :P
>
> I have to admit that (in part from becoming used to Perl's "use strict")
> I'm not entirely enamored of how Lua handles global versus local
> variables, but as I understand it, anything declared with "local"
> creates an independent variable visible only to code in the same block.
> Sort of like how in C, if you write:
>
>    {
>        int x;
>        for (x = 0; x < 10; x++) {
>            int x = rand();
>            printf("%d\n", x);
>        }
>    }
>    // printf("%d\n", x);  // Fails because "x" is undefined here
>
> the "x" that gets printed is the random number, not the loop counter,
> and the last printf() won't compile because there's no variable "x" in
> scope at that level.  (Admittedly that code is both contrived and poor
> style, but just as an example.)  And since it looks like Lua's dofile()
> processes each file loaded as a separate block, my thought is that
> anything declared local at the top of the script should stay within that
> script and be invisible to other scripts.
>
> I haven't actually tried this, though, so I have no idea whether it will
> work in practice. (:
>
>  --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/0e0ae713/attachment.htm>


More information about the aquaria mailing list