lua-users home
lua-l archive

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


>I not sure which way I lean on this but I was wondering what the current
>official rationale of the no "global a,b,c" policy is.

Our position on this is that we have tried it and it does not solve all
problems.

One of the work versions of Lua 4.1 had a "global" statement that was powerful
enough to solve most problems but not was simple to understand. The lua-l
archives contain a long discussion on this. The outcome was that we decided
that each Lua function should have its own global table, which by default is
inherited from the enclosing funcition (that is, the function that creates
the other function). This global table can be changed individually and can
also have metamethods of course. We find this solution to be very flexible,
even if it requires code to be written to implement the various policies.
But of course, this is completely in line with Lua's philosophy of providing
metamechanisms instead of features.

For concrete examples of how this works, see readonly.lua, trace-globals.lua,
and undefined.lua in test/ in Lua 5.0 (beta).
--lhf