[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Re[2]: require ignores setglobals()
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Fri, 7 Feb 2003 09:24:08 -0200
Peter Hill wrote:
>It did. Now you access the global table _G directly! So Lua4
> old = setglobals(sb) ; blah ; setglobals(old)
>
>becomes in Lua5
> old,_G=_G,sb ; blah ; _G=old
Not true. Try
a=1
sb={a=2}
old,_G=_G,sb ; print(a) ; _G=old
If things were as you said, you'd expect it to get 2, but actually you'd
get an error, because print is not present in sb. Of course, you get 1.
_G is not magical variable. It's not part of the core; it's provided by the
base lib for convenience. In other words, global names are *not* resolved by
indexing _G. They're resolved by indexing whatever getglobals return at the
time (of course, the core knows about the current global table of the current
function being executed and does not call getglobals).
--lhf