lua-users home
lua-l archive

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


On Wed, Dec 1, 2010 at 21:49, Dirk Laurie <dpl@sun.ac.za> wrote:
1. 'load' sees no local variables from the block in which it
   is executed, neither does 'loadin'.
Indeed. 'load()' and 'loadin()' consider the loaded string as if it were a different file.
 
2. 'load' can be appear anywhere in the code, with no change in
   its effect, as long as the function defined by it exists
   by the time it is called.
3. 'function', on the other hand, can see local variables and its
   effect therefore does depend on where in the code it stands.

This sounds correct.

    a = 5
    function foo() return a end
    local a = 18
    function bar() return a end

    foo() --> 5
    bar() --> 18

    a= 2000

    foo() --> 5
    bar() --> 2000

    _G.a = 666

    foo() --> 666
 
-- Pierre-Yves