Mac 下纯lua(二)

Lua库


 

基本函数


assert(v,[,message])

当v时false时,返回message

assert(money >0,"error -1001");

collectgarbage([opt,[arg]]);//垃圾回收相关

collet stop restart count step setpause setstepmul

//查看内存的话是 collectgarbage("count");

error(message,[,level]);

error("This operations is invalid");

_G 全局变量 包含了所有的全局变量和函数

getfenv([f]) 当前函数使用的当前环境 f可以是函数或者数字

getmetable(object)当前对象有关联的元表

ipairs(t)输出连续的数组格式

load(func[,chunkname]))???

loadstring(string,【chunkname】)???

next(table,【index】)

t = {"One","Deux","Drei","Quarto"};

print(next(t,3));//打印出key value // t[3]只打印出value

pairs(t) 遍历object

pcall(f,arg1,...) 函数的保护形势调用

rawget(table,index)等于table【index】

rawset(table,index,value) 等于 table[index] = value;

select(index,...)//???

setfenv(f,table)//设置函数的环境

setmetatable(table,metatable);

tonumber(),tostring()类型转换

type()查看类型//nil,number,string,boolean,table,thread,userdata

unpack(list,[i,[j]]);//

myt = {1,2,3,4,5,5,6,7,78,8,8,9};
print(unpack(myt,3,8))


系统库

常用库有table string math file os


表函数

table.concat(aTable,start,end);//打印表的数值

table.insert(aTable,pos,value)

table.remove(atable,pos);

table.sort(atable,compare)//第二个参数是每次比较后调用


os函数

os.clock();//时钟间隔,执行指令的cpu间隔

os.date();//日期

os.difftime()//时间差

os.remove(filename);//移除文件

os.rename(oldname,newname);//修改文件名

os.time()//时间

os.tmpname();//随机名字


table的通常用法

作为数组

作为哈希表(KEY,VALUE)


.和:的区别

冒号包括自己本身。

 

posted @ 2015-12-14 14:14  风林火山战  阅读(212)  评论(0编辑  收藏  举报