Lua功能范围 [英] Lua function range

查看:126
本文介绍了Lua功能范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我这样做,我会出错.我该怎么办?

I got error if I do like this. What should I do?

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()

推荐答案

使用之前必须声明本地:

locals have to be declared before used:

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()

这篇关于Lua功能范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆