lua-users home
lua-l archive

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


Hi Wim,

thanks for the reply. So if I understood it correctly, not only can
every function have its own "global" table, but it is indeed the case
that each function has a reference to a global table, which, in the
default case, is the top level global table.

So, basically, setglobals() just looks like a weird way to introduce a
dynamic binding mechanism. But, unlike perls 'local' or phps 'global',
you have to explicitely tell each and every function which global
table to use, should you want to use the dynamic binding.

>From the name, and the description, I somehow assumed that it would
really alter the "global" table for the time the setglobals()d function
is active. So, you're right, it is consistent, in a way, but somehow
counterintuitive. If this is the intended behaviour of this function,
I feel that the name should be changed, and there should be in the
finished docs explaining this... 

WC> Bottom line: globals tables are only inherited at function _definition_, not
WC> at function _call_ (unless of course explicitly changed by a setglobals
WC> call.)

upon reading this, one might think that my previous assumption was
correct ;-)

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?

Gunnar