[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Implementing a simple sandbox
- From: Wim Couwenberg <w.couwenberg@...>
- Date: Mon, 23 Jun 2003 10:33:38 +0200
> local args = unpack(arg)
First off, this line does not do what you seem to expect.
The effect is the same as doing
local args = arg[1]
because all other unpacked values are discarded.
> setfenv(2, env)
This will have no effect whatsoever on f because f holds on
to its _own_ environment. Try setfenv(f, env)
> local retval = f(args)
To pass all arguments to f do f(unpack(arg)). The line above
discards all return values but the first (should there
happen to be more.) Try
local retval = {f(unpack(arg))}
and later on return unpack(retval)
> setfenv(2, _G)
The global _G is just there for convenience but has no
special meaning, at least not one that you can count on.
Use getfenv(2) (or, getenv(f)) to save the old environment.
> return retval
Change this to return unpack(retval) as indicated above.
Hope this helps a bit in your experiments.
Bye,
Wim