[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Forward declarations in modules
- From: Vyacheslav Egorov <mraleph@...>
- Date: Thu, 07 Sep 2006 10:14:36 +0700
Try something like this
-- begin code
print "In f"
function g() -- nb! no local keyword
print "In g"
-- end code
Nick Gammon wrote:
function m_installer ()
module ("m", package.seeall)
local g -- forward declare g
function f ()
print "inside f"
g () -- call g
end -- f
local function g ()
print "inside g"
end -- g
end -- module m_installer
m.f () -- error: attempt to call upvalue 'g' (a nil value)
I don't quite get how g is an upvalue. It is just another variable
inside the module. I can make the problem go away by removing the
"local" from the function declaration for g, but I wanted it there
because it really is a local function, I don't even want it exported
as part of the module.
Has anyone any suggestions for how to make this work in the way I
- Nick Gammon