[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: require ignores setglobals()
- From: "Wim Couwenberg" <w.couwenberg@...>
- Date: Fri, 7 Feb 2003 11:02:55 +0100
Hi,
Gunnar Zötl:
> this means that the global table I set before executing code is not
> inherited by the require()d file. Instead, everything defined in the
> external file goes to the initial global table. However, assignments
> within the called functions go to my global table.
>
> Is this behavious intentional?
Well, at least it is consistent [;-)]. If I understand correctly, this is
the case: The "require" function already _has_ a globals table and so it
will use that one, which just happens not to be your sandbox sb! However,
as require is a C function (in Lua 5) it is not possible to change its
globals table. So functions "imported" into your sandbox can provide
backdoors to a "protected" globals table... [:-(]
(Btw, I changed your script to require "incl" instead of "incl.lua".)
To show the effect, introduce a fake require Lua function at the top of your
script:
function require()
a = 1
end
Now run the script... Nothing has changed! Now insert the following line
just before you set the sandbox sb as globals table to "code":
setglobals(require, sb)
and run the script again. You see??
Bottom line: globals tables are only inherited at function _definition_, not
at function _call_ (unless of course explicitly changed by a setglobals
call.)
Bye,
Wim