2011-06-18 60 views
1

如果我这样做,我得到错误。我该怎么办?Lua功能范围

local function one() 
    local function two() 
     local function three() 
      callMe() -- got error here 
     end 
    end 
end 

local function callMe() 
    print ("can't call :(") 
end 

callMe() 
+4

据我所知,该代码是无效的Lua:在功能'one','two'和'three'需要'()'后他们。 –

+0

对不起,我的疏忽。当我在这里编写示例代码时,我很着急,但这不是真正的代码。 – Devyn

回答

6

当地人有之前宣称用于:

local callMe 
local function one() 
    local function two() 
     local function three() 
      callMe() -- got error here 
     end 
    end 
end 
function callMe() 
    print ("can't call :(") 
end 
callMe() 
4

除了缺少()onetwothree,就像巴特煮布锅说,调用three()将错误,因为callMethree的范围之内的本地功能,所以它不知道功能。