jinq0123 / hotfix Goto Github PK
View Code? Open in Web Editor NEWLua 5.2/5.3 hotfix. Hot update functions and keep old data.
License: Apache License 2.0
Lua 5.2/5.3 hotfix. Hot update functions and keep old data.
License: Apache License 2.0
我这边使用,出现问题
test.lua:
local M = {} function M.test() assert(false, "test assert 2") end return M
test.test() will assert and print the stack traceback. But after hotfix, the file name is lost in assert output and traceback:
D:\Jinq\temp\lua>d:\Jinq\tools\lua-5.3.2_Win64_bin\lua53 Lua 5.3.2 Copyright (C) 1994-2015 Lua.org, PUC-Rio > hf = require("hotfix") > t = require("test") > t.test() .\test.lua:4: test assert stack traceback: [C]: in function 'assert' .\test.lua:4: in function 'test.test' (...tail calls...) [C]: in ? > hf.hotfix_module("test") table: 000000000078a6d0 > t.test() [string "local M = {}..."]:4: test assert 2 stack traceback: [C]: in function 'assert' [string "local M = {}..."]:4: in function 'test.test' (...tail calls...) [C]: in ? >
-- helper/test.lua
local test = {}
local t = {}
function test.hello()
print("hello")
end
t.hello = test.hello
function test.func()
t.hello()
end
return test
test.func
couldn't see the update to test.hello
. Below is a possible patch.
From f02c2eab8a56c2033c129a65410b37fbcad6f3cf Mon Sep 17 00:00:00 2001
From: olist <[email protected]>
Date: Thu, 17 May 2018 20:23:31 +0800
Subject: [PATCH] Fix replace_functions()
---
hotfix.lua | 3 +++
1 file changed, 3 insertions(+)
diff --git a/hotfix.lua b/hotfix.lua
index 4adae05..89a0aa9 100644
--- a/hotfix.lua
+++ b/hotfix.lua
@@ -156,6 +156,7 @@ local function replace_functions(obj)
if new_func then
assert("function" == type(value))
debug.setupvalue(obj, i, new_func)
+ replace_functions(new_func)
else
replace_functions(value)
end
@@ -177,6 +178,8 @@ local function replace_functions(obj)
replace_functions(k)
end
if not new_v then replace_functions(v) end
+ if new_k then replace_functions(new_k) end
+ if new_v then replace_functions(new_v) end
end -- for k, v
for k, v in pairs(new) do obj[k] = v end
end -- replace_functions(obj)
--
2.14.2.windows.3
假设一种情况,A模块要更新,新旧模块如下,会发生更新后func1和func2所引用upvalue l 是不同的,这样有隐患:
old:
local M = {}
local l = {}
function M.func1()
end
function M.func2()
l[10] = 10
end
return M
new:
local M = {}
local l = {}
function M.func1()
l[10] = 10
end
function M.func2()
l[10] = 10
end
return M
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.