lua-users home
lua-l archive

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


Try something like this

-- begin code
local g

function f()
 print "In f"
 g()
end

function g() -- nb! no local keyword
 print "In g"
end

f()
-- 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_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 wanted? Thanks.

- Nick Gammon






--
e.v.e