[aquaria] Patch to run Lua scripts as threads

Andrew Church achurch+aquaria at achurch.org
Tue Jun 29 16:49:26 EDT 2010


>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/


More information about the aquaria mailing list