当前位置: 首页 > news >正文

Lua篇笔记

. 和 : 的区别
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
end

end

深拷贝

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

http://www.lryc.cn/news/194584.html

相关文章:

  • 一种更具破坏力的DDoS放大攻击新模式
  • WordPress 常规设置页面调用媒体中心上传图片插入URL(新版可用)
  • Elasticsearch实现检索词自动补全(检索词补全,自动纠错,拼音补全,繁简转换) 包含demo
  • LaunchView/启动页 的实现
  • windows安装npm教程
  • 网络端口验证
  • MongoDB 索引和常用命令
  • 【超详细】win10安装docker
  • JVM调优(一)
  • Parallels Desktop 19中文-- PD19最新安装
  • 【c++】向webrtc学比较1:AheadOf、IsNewerTimestamp
  • 华为云云耀云服务器L实例评测|企业项目最佳实践之docker部署及应用(七)
  • MAC上使用Wireshark常见问题
  • 在C++中++a和a++有什么区别?
  • NewStarCTF2023公开赛道-压缩包们
  • oracle数据库增加表空间数据文件
  • 【08】基础知识:React中收集表单数据(非受控组件和受控组件)
  • 数据结构之堆排序和前,中,后,层序遍历,链式二叉树
  • 多线程中ThreadPoolExecutor.map()中传递多个参数
  • linux centos7 环境下 no such file or directory
  • Nginx 反向代理 SSL 证书绑定域名
  • SpringBoot 集成 JMS 与 IBMMQ 代码示例教程
  • 大模型之Prompt研究和技巧
  • 掌握Golang匿名函数
  • HarmonyOS云开发基础认证---练习题二
  • ffmpeg视频解码器的配置选项含义
  • enter ubuntu boot option in virt-manager
  • 电商运营该如何做 AB 测试
  • go环境部署
  • HTTP/2 中的漏洞