Giter Club home page Giter Club logo

lua-hotfix's Introduction

lua-hotfix

一个 lua 热更新的模块,主要针对一个模块里面的某些局部函数,全局函数更新,并不针对整个模块文件进行更新,并且 做到在更新过程中出现的语法错误时,撤销本次热更,尽可能不让热更新影响整个程序流程,测试用例7 有提到。 对于热更新,我写了一篇博客,可以先了解下 https://www.jianshu.com/p/30416db4f649

依赖

  • lua5.2 版本以上

测试

examples 目录下面有几个测试用例,运行方式如下:

cd examples/test1
lua main.lua

说明

  • 加载新模块
local hotfix = require "hotfix"
hotfix.module(list)

其中 module 参数是一个列表,以数组的形式传入,数组中的每一项,包含旧模块表,以及新模块路径,例如:

{
	{tb1, "./tb1_new.lua"},
	{tb2, "./tb2_new.lua"}
}
这个在测试用例8 中有使用到
  • 更新局部函数,或者表中的函数
fix(name, function)
其中 name 是需要更新的函数名称,function 是新的函数体,如果要更新 tb1 表里面的方法,要用 *__module* 来取代 tb1,因为 tb1 是做为更新模块入口
  • 更新全局函数 对于全局函数的更新,最好函数体里面用到的变量,上值都是全局的,不然容易更新失败

注意

  • 对于更新的函数,如果要添加新的函数,变量调用,需要自己手动声明,但不必赋值
  • 对于同一个模块中,不能出现两个名称一样的函数,保证唯一性,保证热更正确
  • 如果要更新的函数存到一个 hashmap 中,通过 key 来索引函数。这种情况下更新函数也是不起作用的,因为更新后的函数并不会自动存到 hashmap 中

lua-hotfix's People

Contributors

sealindx avatar

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.