您可能会看到package.loaded['test'] == nil,因为您没有连接到 Tarantool 实例。
通常当你连接到 Tarantool 时,你看起来像
connected to localhost:3301
localhost:3301>
似乎您只需进入 docker 容器,然后
运行“tarantool”。这样,您只需运行对您的应用程序一无所知的新 Tarantool 实例。
您可以使用console 命令(在容器中)或tarantoolctl connect login:password@host:port(默认配置tarantoolctl connect 3301 有效,详细信息请参阅here)或attach 连接到tarantool 实例,然后检查package.loaded['test'] 值.
这是重新加载模块代码的简化方法:
test2 = require("test")
local function reload()
package.loaded['test'] = nil -- clean module cache
test2 = require('test') -- update a reference to test2 with new code
end
while 1 > 0 do
test2.p()
end
return {
reload = reload, -- require('app').reload() in your console for reload
}
更复杂但正确的方法是使用package-reload 模块。
以下是您的代码不起作用的解释:
-- Here you require "test" module
-- Lua check package.loaded['test'] value
-- and if it's nil then physically load file
-- from disk (see dofile function).
--
-- Well, you got a reference to table with
-- your "p" function.
test2 = require("test")
-- Here you've already has a reference
-- to "test" module.
-- It's static, you don't touch it here.
while 1 > 0 do
test2.p()
end
然后你做package.loaded['test'] = nil 和
从package.loaded 表中删除一个键。
请注意,您不会因为拥有
“app.lua”文件中的引用(在您的情况下为 test2)。