lua-users home
lua-l archive

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


>btw. I have been told that in lua4, setglobals() did indeed change the
>globals table in the way I assumed it would do. Could one of the
>developers please shed some light on why it was changed to work like
>it does now?

The current setglobals scheme was the outcome of our failed attempt to
introduce a "global" statement. Following our basic goals in Lua, we wanted
to have extensible semantics there too, but it proved too complicated. See
the archives for a full discussion. We then realised* that everything that we
wanted to do could be done simply by allowing each function to have its own
table of globals, in which global names are resolved at run time (not compile
time). For simplicity and no-surprises, each function is born with the same
table of globals as the function that defines it (at run time), but it can be
changed at any moment with setglobals. This scheme is simpler even though you
have to write code to get things like transparent inheritance from the "true"
global table and such. The idea is that recurrent patterns of setglobal usage
will be provided in Lua libraries. But this is the no-frills approach of Lua...

* perhaps it was suggested here as well.
--lhf