广告公司管理制度,兴安盟seo,wordpress 语言设定,ps做网站界面. 和 : 的区别 lua的面向对象 Lua数据类型 nil number bool table string userdata thread function Lua-字符串连接 C#与Lua交互过程及原理 Lua中的闭包 常见的一些Lua功能
热重载#xff1a;
function reload_module(module_name) local old_module _G[module_name] --取…. 和 : 的区别 lua的面向对象 Lua数据类型 nil number bool table string userdata thread function Lua-字符串连接 C#与Lua交互过程及原理 Lua中的闭包 常见的一些Lua功能
热重载
function reload_module(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_module --重新赋值 end
再结合LuaFileWatcher去监听哪些lua文件发生了变化就自动热重载该模块其实实际作用不大
**
禁止全局表创建
**
local global_metatable {} setmetatable(_G, global_metatable)
global_metatable.__newindex function(table, key, value) error(禁止创建全局表: … key) end
递归输出一张表
function printTable(table, indent) indent indent or 0 local indentStr string.rep( , indent)
for k, v in pairs(table) doif type(v) table thenprint(indentStr .. k .. (table):)printTable(v, indent 1) -- 递归增加缩进级别elseprint(indentStr .. k .. .. tostring(v))end
endend
深拷贝
function deepClone(object) local tempTable {} local function _copy(object) if type(object) ~ “table” then return object elseif tempTable[object] then return tempTable[object] end local new_table {} tempTable[object] new_table for key, value in pairs(object) do new_table[_copy(key)] _copy(value) end return setmetatable(new_table, getmetatable(object)) end return _copy(object) end