lua-users home
lua-l archive

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


This sounds like a great solution. - No flags, no switches, no pragmas.
Good. Probably better than Python as you dont get misnamed locals.

If you have no globals to reference would you do:

  function f()    -- OK
    global      -- turns on dmode (only inside f)
    c = 1       -- ERROR; c is undeclared
  end

This would be a redundant question if you inherited the dmode.

N


From: Roberto Ierusalimschy
>> the following could work:

  a = 3;  -- OK, default is declaration mode (dmode) off

  function f()    -- OK
    global b        -- turns on dmode (only inside f)
    b = 1
    c = 1       -- ERROR; c is undeclared
  end

  x = 4;      -- OK; out of scope of "global b", so back to dmode off

On the other hand, if the chunk starts with "global", then everything
in it will inherit the dmode on.

-- Roberto