Giter VIP home page Giter VIP logo

hotfix's People

Contributors

jinq0123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hotfix's Issues

Hotfix will lost file name info

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 ?
>

Doesn't work in some cases

-- 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

hotfix.lua的update_func处理会有bug

假设一种情况,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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.