lua调用不同lua文件中的函数

a.lua和b.lua在同一个目录下

a.lua调用b.lua中的test方法,注意b中test的写法 _M 和 a中调用方法:

b.lua

local _M = {}

function _M.test()

ngx.say("hello test!")

end

return _M

a.lua

local test = require("b")

if not test then

ngx.say("Failed to require b!")

return

end

test:test()

/openresty/lualib/resty里面的写法可参考

参考链接:https://my.oschina.net/chrisforbt/blog/492999 --------------------- 作者:PureMastiff 来源:CSDN 原文:https://blog.csdn.net/Lovegengxin/article/details/80585634 版权声明:本文为博主原创文章,转载请附上博文链接!