[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua Library Design Workshop
- From: Peter Shook <peter.shook@...>
- Date: Sat, 23 Feb 2002 10:12:00 -0500
Roberto Ierusalimschy wrote:
> The second is that there is no easy and simple way to avoid using
> the dot notation for every reference to an "imported" object. Then I
> presented an idea we have been discussing before (the "mechanism that
> forces variable declarations").
>
> The mechanism is as follows: first, we start with the "obvious" global
> declarations:
>
> global a,b,c
>
> But then we add an optional item to the declaration, that states in what
> table those "globals" live (yes, it is strange, "global" does not declare
> globals anymore... but let us forget that for now). So, if you put functions
> 'b' and 'c' in a module "m", you can access them directly after the
> following declaration:
>
> global (m) b, c
>
> Roughly, that translates to "local _t = m", and then any access to b (or c)
> is translated to "_t.b" (or _t.c). Instead of a list of names, we can also
> use a single "*", which means a default for all non-declared globals.
>
Thanks for the update. I really like this idea, although the syntax is
weird. How about something more like:
Public = {}
local a,b,c in Public
function a(x) return b+c end
would be equivalent to:
function Public.a(x) return Public.b + Public.c end
- Peter