You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
local function hot_load_file(file)
local code = nnfile.readall(file)
local var = 1
local injector = require("nninjectcode") -- 直接用的skynet的injectcode.lua改名
local ok, test_module = injector(code, nil, 0)
print("Initial version:", test_module.version)
print("var3", var)
print("Initial value:", test_module.get_value())
print("var4", var)
return test_module
end
-- 创建一个测试模块文件
local test_module_path = "hot_update_test.lua"
local file = io.open(test_module_path, "w")
file:write([=[
local M = {}
print("_G.var:", _G.var)
var = var or 2
print("_G.var:", _G.var)
var = var + 1
M.version = 1
function M.get_value()
print("var", var)
var = var + 1
print("var", var)
return "original value"
end
return M
]=])
file:close()
print("首次加载模块")
local test_module = 1
-- test_module = require("hot_update_test")
test_module = hot_load_file(test_module_path)
print("Initial version:", test_module.version)
print("Initial value:", test_module.get_value())
输出结果:
首次加载模块
_G.var: nil
_G.var: nil
Initial version: 1
var3 2
var 2
var 3
Initial value: original value
var4 2
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
我在测试热更新功能时,使用了skynet里的injectcode.lua模块,但测试结果不对,测试代码如下,运行结果在后面:
输出结果:
这里主要是这个var4 2不对,正确结果应该是var4为3才对,不知道是什么哪里出问题了。
Beta Was this translation helpful? Give feedback.
All reactions