lua模块

2018-11-02  本文已影响0人  Mad_Elliot
--module.lua文件
tab = {}
tab.constant = "这是一个常量"
function tab.func1()
    io.write("这是一个公有函数\n")
end

local function func2()
    print("这是一个私有函数")
end

function tab.func3()
    func2()
end
return module
--test_module.lua文件
require("module")
print(tab.constant)
tab.func1()
--func2() 当去掉了local之后,值直接访问方法二
tab.func3()

>> 这是一个常量
>> 这是一个公有函数
>> 这是一个私有函数
上一篇 下一篇

猜你喜欢

热点阅读