[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Redefine the module() function
- From: Aladdin Lampé <genio570@...>
- Date: Mon, 14 Jan 2008 12:03:51 +0000 (UTC)
Patrick Donnelly <batrick.donnelly <at> gmail.com> writes:
>
> Unless you changed the environment of the original module function
> (not yours), then the behavior be identical. You've also not really
> told us what _is_ going wrong.
>
> Because you say that you have the redefined module function in an
> environment different from the original, when you load a new module,
> it will not see the redefined module function (because the redefined
> module function is not in the real global environment). Is that your
> problem?
>
You're right. Here is the actual code I use for testing (badly transposed in
my previous post):
"testmod.lua":
local package = require "package"
local original_module = module
function module(modname, ...)
original_module(modname, ...)
package.loaded[modname].hello = "hello you"
return m
end
require 'mymod'
mymod.hi()
"mymod.lua":
module 'mymod'
function hi() print(hello) end
And the error I get is:
lua: testmod.lua:11: attempt to call field 'hi' (a nil value)
stack traceback:
testmod.lua:11: in main chunk
[C]: ?
Thanks for your insight,
Aladdin