Oh, I see. I thought those were in separate files for some reason.
You can't use a local function (or a local anything, really) before it's been defined. A local can only be accessed from the point it's created up until its scope closes. A global can be used from anywhere, so long as it's been created first.
All you need to do is re-order your function definitions, or else pre-create the locals.
Amended on Tue 21 Feb 2012 06:19 AM (UTC) by Twisol
Message
Oh, I see. I thought those were in separate files for some reason.
You can't use a local function (or a local anything, really) before it's been defined. A local can only be accessed from the point it's created up until its scope closes. A global can be used from anywhere, so long as it's been created first.
All you need to do is re-order your function definitions, or else pre-create the locals.
wang_test={}
local function foo2 ()
return function ()
print('This is my test')
end --
end --local function f_2
function wang_test.foo1(str)
local _f=foo2 ()
_f()
end --function wang_test.foo1()
Amended on Tue 21 Feb 2012 05:15 AM (UTC) by Yeedoo
Message
In a module or package. What's the different with the function and the local function?
Just the local function cant be seen from outside the module?
I tried to setup a module with a local function
wang_test={}
function wang_test.foo1(str)
local _f=foo2 ()
_f()
end --function wang_test.foo1()
---------------------------------
local function foo2 ()
return function ()
print('This is my test')
end --
end --local function f_2
but When i use the module, i got that attempt to call global 'foo2' (a nil value)
What's the problem? Thank you!
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.