lua
http://www.cnblogs.com/whiteyun/archive/2009/08/10/1543139.html 加载lua文件 require("文件名没有后缀.lua") 加载的时候会执行此文件的所有不是方法的内容,此时如果你在最后 return ""后面不能再写内容了, local con = require "" ?con 将会接收到你返回的内容 字符串 string.format("整形?%d 转换",?1) ? string.format("%s X %s",“s1”,“s2”)
string.byte("01") ? ? 0:?对应的ASCII码 48 ? ? string.byte("01”,2) ? ?1:?对应的ASCII码 49 string.len(“12332”) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?5 正则表达式 数据结构 table local tab = {"a","b","c","d"} tbl = {"alpha","beta",[3] = "uno",["two"] = "dos"} for i,v in ipairs(tbl) do? ? --输出前三个 ? ? print( tbl[i] ) end for i,v in pairs(tbl) do? ? --全部输出 ? ? print( tbl[i] ) end tbl = {"alpha","gamma"} table.concat(table,sep,? start,end) table.concat(tbl,nil(分隔符 nil无),1(默认start),? 2(默认end))? table.insert(table,pos,value) table.insert(tbl,"delta") 默认最后 table.insert(tbl,3,"zeta")? 第三个位置前插入 table.maxn(table) table.maxn()函数返回指定table中所有正数key值中最大的key值. 如果不存在key值为正数的元素,则返回0. 此函数不限于table的数组部分. tbl = {[1] = "a",[2] = "b",[3] = "c",[26] = "z"} print(#tbl) ? 3? ? ? -- 因为26和之前的数字不连续,所以不算在数组部分内 print(table.maxn(tbl))? ? 26 tbl[91.32] = true print(table.maxn(tbl))? ? 91.32 数学
math.random(0,3) ? ? —随机0~3包括首尾 math.ceil() ? ? ? ? ? ? ? ? 向上取整 math.floor(11.9) ? ? ? ?11 向下取整 时间?
local date = os.date("*t",os.time()); date.year date.month date.day date.hour date.min date.sec 其他
print(' '); print(' '..''); require "xxx.lua" 特别
1.local titleStr = title ==nil and "No title" or title ?
2.if nil then ? ? ??—不执行 ? ?end 3. ? testA(12,'fewf',32);local function testA( ... ) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? --多个参数用法 ? ? for n=1,select('#',...) ?do ? ? ? ? local e = select(n,...) ? ? ? ? print(e); ? ? end end 4. ?a = "4" + "5" ? ? ? ? ? ? ? ? ? ? ? ? ? a==9 ? ? ?tostring(2) + tostring(4) ? ? ? ? == 6 5.key 不能是字符串 ‘aa’='bb'错? 2.优先遍历32,30默认的key是1,2 local? test = {32,aa="bb",cc='33',30}; for key,value in pairs(test) do ? ? print(" ? "..key.." ? ? "..value) end 1 ? ? 32 2 ? ? 32 aa ? ? bb cc ? ? 33 lua内存 http://colen.iteye.com/blog/578146
补充说明: ? collectgrabage(opt [,arg]) ? 功能:垃圾收集器的通用接口,用于操作垃圾收集器 ? 参数: ? ? ? opt--操作方法标志 ? ? ? "stop" : 停止垃圾收集器 ? ? ? "restart" : 重启垃圾收集器 ? ? ? "collect" : 执行一次全垃圾收集循环 ? ? ? "count" : 返回当前Lua中使用的内存量(以KB为单位) ? ? ? "step" : 单步执行一个垃圾收集.步长"size"由参数arg指定.如果完成一次收集循环,将返回True ? ? ? "setpause" : 设置arg/100的值作为暂定收集的时长 ? ? ? "setstepmul" : 设置arg/100的值,作为步长的增幅(即新步长 = 旧步长*(arg/100))? C++加载 register.lua文件夹之后 调用 LoginScene.show 方法,这个时候Lua文件有错会 抛到 __G__TRACKBACK__? 里打印信息 register.lua xpcall(LoginScene.show,__G__TRACKBACK__) function __G__TRACKBACK__(msg) ? ? print("----------------------------------------") ? ? print("LUA ERROR: ? " .. tostring(msg) .. "n") ? ? print("123? ? ? ? ? "..debug.traceback())--像更加上一次的 lua 代码提交 ? ? print("----------------------------------------") end type() table number string function (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |