lua-users home
lua-l archive

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


Nick Gammon wrote:
However, for documentation reasons I wanted to put f (the exported function) near the top of the file, and have g (the internal function) further down.

function m_installer ()

  module("m", package.seeall)

  -- forward declare g
  local g

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

  function g()
    print"inside g"
  end
end

m_installer()
m.f()


You were very close.  Remember that this syntax:

local function g() end

is equivalent to

local g = function() end

and that the local statement creates a new local.

					-Mark