lua-users home
lua-l archive

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


>         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