Lua 自定义模块

it2023-05-21  81

 

自定义文件self_func.lua

--定义模块 local self_func= {} --为模块声明一个say的方法 function self_func:say() return "hello word!!" end function self_func:say1(str) print(str) end --本模块其他函数调用say1()时用 self:say() function self_func:say2(str) self:say(str) return "hello word!!" end --返回关键字 return self_func

其他文件调用:

local self_func = require("self_func") res = self_func:say()

 

最新回复(0)