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"}
访问:tab[1]  table[2] 。。。
local tab = {[60]="a", [61]="b", [62]="c", [63]="d"}
访问:tab[1]  table[60] 。。。
声明:tab[64] = "e"
local tabb = {aa = "a", bb = "b", cc = "c", dd = "d"}
访问:tabb.aa 。。。
声明:tabb.ee = "e"

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", "beta", "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.优先遍历3230默认的key12

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







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值