[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Redefine the module() function
- From: "Patrick Donnelly" <batrick.donnelly@...>
- Date: Mon, 14 Jan 2008 05:59:17 -0700
Here is your problem.
function module(modname, ...)
original_module(modname, ...) <-- that
When you call the module function, it changes the environment of the
caller. In this case it's your redefined module function. Thus, when
you define the function "hi" inside mymod.lua, it is actually placed
in the global environment. If you are going to redefine the module
function you are going to need to do a little more work:
local setfenv, getfenv = setfenv, getfenv
function module(modname, ...)
local myenv = getfenv(1)
original_module(modname, ...)
local newenv = getfenv(1)
setfenv(2, newenv)
setfenv(1, myenv)
-- do whatever else you wanted
end
HTH,
--
-Patrick Donnelly
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."
-Will Durant