lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Rici Lake wrote:

On 17-Aug-05, at 9:27 AM, Chris Marrin wrote:

I am using the wrong term. When I say "locals" I mean properties of the "local namespace", which is the environment being used by a particular function. So, if I have module 'a' and I want to import some or all of its properties into the environment of a function, I would just copy the property references from the module to the environment. They are both just tables, right?


You could do that, but it's not easy to see what advantages that would give you aside from saving a few keystrokes, I suppose. The package namespace is in effect the public interface to a package; I wouldn't have thought that importing random names into it would be a good idea.

I see it most often for "standard" things like Math. Rather than importing each one separately you can bring in all the functions, like this maybe:

    import("Math","all")
    local r = min(1,log(sin(PI*2*fraction)))

which looks a lot nicer than:

    require"Math"
    local r = Math.min(1,Math.log(Math.sin(Math.PI*2*fraction)))

IMHO. I am writing an app aimed at more casual users, so simplifications like this are important to me...

--
chris marrin                ,""$,
chris@marrin.com          b`    $                             ,,.
                        mP     b'                            , 1$'
        ,.`           ,b`    ,`                              :$$'
     ,|`             mP    ,`                                       ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'