lua 字符转换 utf8
function utf8(decimal) -- convert unicode code point to utf-8 encoded character string if decimal<128 then return char(decimal) end local charbytes = {} for bytes,vals in ipairs(utf8markers) do if decimal<=vals[1] then for b=bytes+1,2,-1 do local mod = decimal%64 decimal...标签: lua
lua 数字转换 带千位间隔符
--获取数字带千位间隔符 function Fishing_NumberFormat(num, deperator) local str1 = "" local str = tostring(num) local strLen = string.len(str) if deperator == nil then deperator = "," end deperator = tostring(deperator) for i = 1, strLen do str1 = strin...标签: lua
lua获取小数点后几位
--获取小数点后几位 function GetPreciseDecimal(nNum, n) if type(nNum) ~= "number" then return nNum; end n = n or 0; n = math.floor(n) local fmt = '%.' .. n .. 'f' local nRet = tonumber(string.format(fmt, nNum)) return nRet; end标签: lua
lua 中pairs 和 ipairs区别
lua 中pairs 和 ipairs区别 标准库提供了集中迭代器,包括迭代文件每行的(io.lines),迭代table元素的(pairs),迭代数组元素的(ipairs),迭代字符串中单词的 (string.gmatch)等等。LUA手册中对与pairs,ipairs解释如下: Returns three values: an iterator function, the table t, and 0, so that the construction for i,v in ipairs(t) do body...标签: lua
uLua Unity工作机制
最近有人问到ulua 的工作原理,似乎没有自己总结过,接下来我做一个简单的总结,同时也结合网上朋友的总结说一下: 基于ulua 1.25版本,开启C#类型动态注册. 一. 步骤 注册需要Wrap的C#类型. 在WrapFile.cs类中,使用_GT(typeof(XXX)), 注册需要Wrap的C#类型 注册的C#类型被包装成BindType对象,在BindType构造函数里获取注册类型的类名,注册给Lua的名称,基类名称,Wrap的文件名称等信息,并保存在相应的Bin...标签: Unity3D-优化性能 lua
lua Queue
--实现队列与双端队列 Queue={} function Queue:new() return {first = 0, last = -1} end function Queue:pushFront(queue, value) queue.first = queue.first-1 queue[queue.first]=value end function Queue:pushBack(queue, value) queue.last = queue.last+1 queue[ queue.last ]=value end...标签: lua
lua 实现 Queue 队列与双端队列
-- 实现队列与双端队列 local Queue = class("Queue") function Queue:ctor() self.first = 0 self.last = -1 end function Queue:pushFront(queue, value) queue.first = queue.first - 1 queue[queue.first] = value end function Queue:pushBack(queue, value) queue.last = queue.last + 1...标签: lua
lua 常用的一些utils
-- ---------------------- for array ---------------------------- --[[ -- func: 函数把两个或多个数组合并为一个数组,并去掉重复项 -- -- params: -- @t1 array key-value in table is int --]] function array_merge(t1, t2, ...) if(t1 == nil and t2 == nil) then return {} end print("t1.len",#t1) print("t2.len",...标签: lua
utils for lua
--[[ -- filename: utils.lua -- -- * common functions put here -- -- --]] -- ---------------------- for array ---------------------------- --[[ -- func: 函数把两个或多个数组合并为一个数组,并去掉重复项 -- -- params: -- @t1 array key-value in table is int --]] function array_merge(t1, t2, ...) if(t1 =...标签: lua