02 2013 档案
摘要:--多重继承local function search(k,plist) for i=1,#plist do local v=plist[i][k] -- 取一个基类 if v then return v end endendfunction createClass(...) local c={}; local parents={...}; setmetatable(c,{__index=function(t,k) return search(k,parents) end } ); c.__index=c; function c:new(o) o=o or {}; setmetat...
阅读全文
摘要:for i = 1,10 do repeat if i == 5 then break end print(i) until trueendprint("----------------------------------")function foo(i, max) if i == 5 then return foo(6, max) -- continue to i=6 end print(i) if i == max then return else return foo(i+1, max) endendfoo(1, 10)
阅读全文
摘要:function LuaError(...) local strContent="" for i=1,arg.n,1 do strContent = tostring(strContent)..tostring(arg[i]) if i ~= arg.n then strContent = strC
阅读全文
摘要:function getrandom(nMax) math.randomseed(tostring(os.time()):reverse():sub(1, 6)) local tab = {} local tabFin = {} local Rand for i=1,nMax do table.insert(tab,i) end for i=1,table.getn(tab) do Rand = math.random(table.getn(tab)) while tab[Rand] == nil do Rand = math.random(table.getn(tab)) end...
阅读全文
摘要:函数名描述示例结果pi圆周率math.pi3.1415926535898abs取绝对值math.abs(-2012)2012ceil向上取整math.ceil(9.1)10floor向下取整math.floor(9.9)9max取参数最大值math.max(2,4,6,8)8min取参数最小值math.min(2,4,6,8)2pow计算x的y次幂math.pow(2,16)65536sqrt开平方math.sqrt(65536)256mod取模math.mod(65535,2)1modf取整数和小数部分math.modf(20.12)200.12randomseed设随机数种子math.ra
阅读全文
摘要:选中工->右键属性->配置属性->常规->警告等级->关闭所有警告
阅读全文
摘要:Lua代码function table2json(t) local function serialize(tbl) local tmp = {} for k, v in pairs(tbl) do local k_type = type(k) local v_type = type(v) local key = (k_type == "string" and "...
阅读全文
摘要:function FGUtilStringSplit(str,split_char) ------------------------------------------------------- -- 参数:待分割的字符串,分割字符 -- 返回:子串表.(含有空串) local sub_str_tab = {}; while (true) do local pos = string.find(str, split_char); if (not pos) then sub_str_tab[#sub_str_tab + 1] = str; break; end local sub...
阅读全文