cloudwu / luareload Goto Github PK
View Code? Open in Web Editor NEWreload a lua module
reload a lua module
看代码 luareload 大致明白在reload的时候做了这些事情:
但还是有些不明白(毕竟代码里面注释也写的少)其所以然,
吴老师能讲一下这个reload工具去做lua reload 的一些思路吗?
万分感谢
应用到skynet中的时候发现,因为codecache的存在, sandbox的require第二次require同一文件的话,无法更新,所以要和skynet结合使用的话是否findloader改成返回load和load需要的参数?
1.不能正确热更的代码:
local a = 10
local data = {
a = a,
c = c,
}
function data.globalTest()
return c
end
return data
如果原有模块没有定义globalTest函数,因为globalTest在沙盒中被require,其env指向的是沙盒内的global,会有错误。
2.修改方案:
假如有原有函数,可以设置原有函数的env;但是因为是新增函数,按照一般理解来看,这里的env应该可以理解成_G,根据项目约束,我们可以增加代码如下:
if type(v) == "function" then
debug.setfenv(v, _G)
end
reload.lua:125: bad argument #1 to 'ipairs' (table expected, got nil)
但是使用skynet修改版的Lua运行就没有问题=.=
例如新增
function mod.foo4()
print(a)
end
a无法和旧的a做关联。
经过排查觉得 function match_objects(objects, old_module, map, globals)内的 map[obj] = old_one有误。
我现在是改为 map[obj] = old_one or map[obj] or false,经过测试能解决这个问题。
在 reload 重新加载 mymod 后添加下面打印报错了
print("===mymod.getinfo", mymod.getinfo)
下面是报错
lua: ./reload.lua:41: attempt to index a nil value (upvalue 'dummy_module_cache')
stack traceback:
./reload.lua:41: in function <./reload.lua:41>
[C]: in function 'tostring'
[C]: in function 'print'
test.lua:34: in main chunk
[C]: in ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.