文件 test1.lua
package.path = ROOT_PATH .. "/?.lua;;"
ngx.header.content_type = "text/html"
globalV1 = {}
ngx.say("in main file addr of globalV1:")
ngx.say(tostring(globalV1) .. "<br>")
local testTable = require "test4"
testTable.func()
文件 test2.lua
local testTable = {}
testTable.func = function()
ngx.say("in test file, addr of globalV1:")
ngx.say(tostring(globalV1) .. "<br>")
end
return testTable
code cache 打开,请求第二次,运行结果:
in main file addr of globalV1: table: 0x412f1c40
in test file, addr of globalV1: table: 0x412f1550
这是为什么呢?怎么解决?