lua-users home
lua-l archive

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


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