lua热更新
热更新,不停机更新,是在不重新下载安装包,甚至不重启游戏的情况下对游戏进行更新。
12345678910111213function (module_name) local old_module = _G[module_name] package.loaded[module_name] = nil require (module_name) local new_module = _G[module_name] for k, v in pairs(new_module) do old_module[k] = v end package.loaded[module_name] = old_moduleend
可以对旧模块完成更新。
2.2 lua 基础数据类型
lua 是一门极其精简的语言,内置类型只要nil,boolean,number等三种基本类型,以及string,table等二种组合类型。没有C/C++ 等语言中的class、struct等复杂类型,这些类型可以通过table来实现。同时,不同于其他语言(如C/C++和java),function在lua中也作为一个一级类型。
nilnil 是一种类型,Lua 将 nil 用于表示“无效值”。
一个变量在第一次赋值前的默认值是 nil
将nil 赋予给一个全局变量就等同于删除它.
openresty 中提供了另一种表示空值的类型ngx.null.
nil在lua中有其特殊意义,如果一个变量被设置为nil,就等于说该变量未定义,与无穷无尽的其他未定义的变量一样。那么,如果把redis查询为空的结果设置为nil,就无法把”查询为空”和“未定义”区分开来了,例如在一个table中,一个key对应一个value,如果将该value设置为nil,则相当让key凭空消失,这显然是不合理的。所以必须用一个userdata类型的独特的值来表示这种查询为空,但又不等同于未定义的变量,例如ngx.nu ...
Lua-table
by Mingyang Guan2017/9/16 14:00:13
table.pack() and table.unpack() pack函数主要是获取一个索引从一开始的table,并对这个table预定义一个字段n,表示该表的长度。例如:
th> t = table.pack("a", "b", "c")
th> t
{
1 : "a"
2 : "b"
3 : "c"
n : 3
}
table.unpack主要是获取table中的元素,用法:unpack(table, [start], [end])。
th> v1, v2, v3, v4 = table.unpack(t)
th> v1, v2, v3, v4
a b c
其中v4返回值为nil
systematic evaluation of isoform function in literature reports of alternative splicing
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS" } }
});
Classify distinct functions of isoforms
Literature-based analysis of experimental evidence for functionally distinct splice isoforms (FDSIs) for over 700 human & mouse genes
Result: fewer than 10% of genes have solid experimental evidences of FDSIs.
Main
Some question
Do most genes really have multiple functional isoforms?
Given that only 3% of human and 9% of mouse genes have evidence for FDSIs
Trying to lin ...
design pattern - strategy pattern in c++ and lua
What is Strategy Pattern
Example in C++
Example in Lua
Strategy Pattern Wiki
In computer programming, the strategy pattern (also known as the policy pattern) is a behavioural software design pattern that enables selecting an algorithm at runtime.
一一一一一一一一一一一一一一一一一一一一一一一一
© Hung-Chi's Blog
https://hungchicheng.github.io/2017/09/25/Design-Patterns-Strategy-Pattern-in-lua-and-C++/
一一一一一一一一一一一一一一一一一一一一一一一一
(adsbygoogle = window.adsbygoogle || []).push({});
What is Strat ...
design pattern - decorator pattern in c++ and lua
What is Decorator Pattern
Example in C++
Example in Lua
Decorator Pattern Wiki
In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class. The decorator pattern is often useful for adhering to the Single Responsibility Principle, as it allows functionality to be divided between classes with unique areas of co ...
design pattern - observer pattern in c++ and lua
What is Observer Pattern
Example in C++
Example in Lua
Observer Pattern Wiki
The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
一一一一一一一一一一一一一一一一一一一一一一一一
© Hung-Chi's Blog
https://hungchicheng.github.io/2017/09/29/Design-Patterns-Observer-Pattern-in-lua-and-C++/
一一一一一一一一一一一一一一一一一一一一一一一一
...
lua 协程和状态
协程(协同式多线程)是一种用户级的非抢占式线程。用户级是指它的切换和调度由用户控制,非抢占指一个协程只有在其挂起(yield)或者协程结束才会返回。协程和C线程一样,有自己的堆栈,自己的局部变量,自己的指令指针,并且和其它协程共享全局变量等信息。用户可以实现自己调度协程,这主要得益于yield函数可以自动保存协程当前上下文,这样当挂起的协程被唤醒(resume)时,会从yield处继续向下执行,看起来就像是一个”可以返回多次的函数”。协程还有一个强大的功能就是可通过resume/yield来交换数据,这样使得它可以用于异步回调:当执行异步代码时,切换协程,执行完成后,再切换回来(附带异步执行结果)。由于切换都是用户控制的,在同一时刻只有一个协同程序在运行(这也是和传统线程最大的区别之一),因此无需考虑同步和加锁的问题。
Lua协程的相关函数封装在coroutine中,对应的 C API为lua_newthread,lua_resume等。Lua文档中的thread和coroutine是一个概念,但与操作系统的线程是两个东西。
C API通过lua_State维护一个协程的状态(以及Lu ...
9 why's to ask when evaluating a distributed database
When I first started building TiDB with my co-founders, we encountered countless challenges, pitfalls, and critical design choices that could have made or broken the project. To build an enterprise-grade distributed database like TiDB from scratch, we have to constantly make difficult decisions that balance the speed of development with long-term considerations for our customers and our team.
Three years and two big releases later, TiDB 2.0 is now deployed in-production in more than 200 compani ...
design pattern - factory pattern in c++ and lua
What is Factory Pattern
Example in C++
Example in Lua
Factory Pattern Wiki
In object-oriented programming (OOP), a factory is an object for creating other objects – formally a factory is a function or method that returns objects of a varying prototype or class from some method call, which is assumed to be “new”. More broadly, a subroutine that returns a “new” object may be referred to as a “factory”, as in factory method or factory function. This is a basic concept in OOP, and for ...


