1 --模块与包 2 3 -- 定义一个名为 module 的模块 4 module={} 5 6 module.consta="这是一个常量" 7 8 function module.func1() 9 io.write("func1共有函数 ") 10 end 11 12 local function func2() 13 io.write("func2私有函数 ") 14 end 15 16 function module.func3() 17 func2() 18 end 19 20 return module
1 --加载module.lua模块,不需要Lua后缀 2 require("module") 3 4 print(module.consta) 5 6 module.func3() 7 module.func1() 8 9 ---私有函数无法打印,会报错 10 --module.func2() 11 12 --数组 table model 打印名称都是地址 13 print(module) 14 15 16 17 --引入dll so 18 19 --这是 linux 平台下 20 --local path = "/usr/local/lua/lib/libluasocket.so" 21 --这是 Window 平台下 22 --path = "C:\windows\luasocket.dll" 23 --local f = assert(loadlib(path, "luaopen_socket")) 24 --f() -- 真正打开库