Lua hot update introduction

1. Principles: lua interacts with the c# interface through the built-in virtual machine

The lua virtual machine is written in c. Using a virtual machine to interpret lua code does not require executable memory permissions, so
jit that can hot update c# needs executable memory permissions, and interprets il code as machine code execution, so it cannot hot update
lua and C# interaction can call the c# method through reflection, but the efficiency is low, so with the wrap file, the c# method is bound to the lua calling interface, and it can be called without using reflection (this is similar to ilruntime)

2. Use articles.

1) lua object-oriented

__index (set metatable and lookup)

Search the original table first, and then search the metatable. If the metatable is a function, the original table and key will be passed as parameters to the metatable method.

__newindex (update metatable)

Only update the data in the metatable, and can only be called through the metatable. (It can be used to monitor the update of the original table)
The __newindex metamethod is used to update the table, and __index is used to access the table.
When you assign a missing index to a table, the interpreter looks for the __newindex metamethod: if it exists, it calls this function without assigning.

metatable inheritance

Determine whether there is a meta method, if there is no group setmetatable(cls, __Index = base_cls)

2) lua table weak reference weak table, etc. (do not enter the reference counter for calculation)

_mode = k, v When there is no strong reference, gc will automatically release the corresponding data
Useful, cache related code, similar to weak reference of c#

3) Interaction between lua and c#

link: link

4) lua data structure

The combination of hash and array, use the array structure when the data is relatively continuous, and use the hash structure when the data is not continuous enough

5) lua global variables (disable global variables)

1. 禁用方法 _G.require = function(val) error("Require can not be use in Framework",val,debug.traceback()) end
2. 禁用全部:setfenv(1, {});

Guess you like

Origin blog.csdn.net/qq_28976599/article/details/124788172