
lua小技巧
lpl312905509
这个作者很懒,什么都没留下…
展开
-
lua 自实现pairs
文章目录1.实现一个简单的pairs2.实现对象的pairs1.实现一个简单的pairslocal tbl = {}function GenerateData() --构造一个哈希 table for i = 1,10 do local value = math_random(1,100000) tbl[value] = value endend--自己实现的pairsfunction selfPairs(tbl,key) --原创 2021-06-04 13:45:31 · 1606 阅读 · 0 评论 -
lua unpack有点小坑
function c(a,b,c,d,e) print(a,b,c,d,e) endfunction a() local temp = {nil,1,nil,3,nil} local temp1 = {nil,1,2,3,nil} c(unpack(temp))enda()https://segmentfault.com/a/1190000009404985原创 2020-08-27 07:46:30 · 412 阅读 · 0 评论 -
C/C++ 中遍历 Lua table 完整版
https://blog.youkuaiyun.com/naonao8355/article/details/11192307原创 2020-07-23 15:34:28 · 457 阅读 · 0 评论 -
lua 简单判断系统的方法
local delimeter = package.config:sub(1,1)print(delimeter)windowslinux原创 2020-07-03 10:27:37 · 1397 阅读 · 1 评论 -
Lua5.1 非userdata __gc的使用方法
local function setmt__gc(t, mt) local prox = newproxy(true) getmetatable(prox).__gc = function() mt.__gc(t) end t[prox] = true return setmetatable(t, mt)endfunction ooo( o ) print(o[1])endmt = {__gc = ooo}list = {}for i = 1,3 do原创 2020-05-25 00:34:37 · 397 阅读 · 0 评论 -
lua 正则表达式
--[[.(点): 与任何字符配对%a: 与任何字母配对%c: 与任何控制符配对(例如\n)%d: 与任何数字配对%l: 与任何小写字母配对%p: 与任何标点(punctuation)配对%s: 与空白字符配对%u: 与任何大写字母配对%w: 与任何字母/数字配对%x: 与任何十六进制数配对%z: 与任何代表0的字符配对%x(此处x是非字母非数字字符): 与字符x配对. 主...原创 2020-03-05 17:04:23 · 2100 阅读 · 0 评论 -
vs生成lua动态库并如何使用动态库
本博客采用vs2015以及lua5.3版本进行lua动态库以及使用 工具这里就不赘述了,网上很多生成lua动态库的步骤一.建立vs c++控制台 dll程序二.设置编译相对输出路径…/…/…/bin三.设置输出 导入库相对路径…/…/…/lib四.添加LUA_BUILD_AS_DLL宏相对路径指的是目录结构很清晰,如果和我不一样,自行调整相对路径即可。第一步 创建工程目录结构如下...原创 2020-01-30 22:56:58 · 1472 阅读 · 0 评论 -
lua 协程调用顺序
_G.id = _G.id or 0function getId() _G.id = _G.id + 1 return _G.idend_G.coroutineList = _G.coroutineList or {}function fun1(id,oneResumeparam) local coroutine = _G.coroutineList[id] print(cor...原创 2020-01-19 15:04:51 · 399 阅读 · 0 评论 -
Lua格式化分离字符串
项目中经常会遇到分离字符串 如"2019-11-23 12:23:56" 那怎么将这些数字分离出来呢,下面直接上代码讲解。其他情况也类似function split(input, delimiter) input = tostring(input) delimiter = tostring(delimiter) if (delimiter=='') then return ...原创 2020-01-14 11:12:59 · 331 阅读 · 0 评论 -
Lua 游戏 实现合并同类物品
--根据type和id生成一个唯一的索引local function generateIndex( ty,id ) assert(type(ty) == "number") assert(type(id) == "number") return ty * 1000000 + idendlocal function ungenerateIndex( index ) local ty ...原创 2019-09-02 10:21:43 · 792 阅读 · 0 评论 -
lua 实现位操作代码及案例
bit = bit or {}bit.data32 = {}for i=1,32 do bit.data32[i]=2^(32-i)endfunction bit._b2d(arg) local nr=0 for i=1,32 do if arg[i] ==1 then nr=nr+bit.data32[i] ...原创 2019-06-30 23:42:00 · 1871 阅读 · 0 评论 -
lua 计算utf8字符串的长度
function utf8len(input) local len = string.len(input) local left = len local cnt = 0 local arr = {0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc} while left ~= 0 do local tmp = string....原创 2019-06-29 09:38:27 · 581 阅读 · 0 评论