TA的每日心情 | 慵懒 2015-1-8 08:46 |
---|
签到天数: 2 天 连续签到: 1 天 [LV.1]测试小兵
|
1.当处理数据文件时,一般总是写比读来得简单,因为写文件时我们有完全的控制,读时却不能确保碰上什么样的数据,我们需要保证健壮的程序能优雅地处理各种各样的错误数据.
2.
Entry
{
title = "Tecgraf",
org = "Computer Graphics Technology Group, PUC-Rio",
url = "http://www.tecgraf.puc-rio.br/",
c,
};
语法含义是Entry函数调用,传入参数为指定的table.
3.a.Metatables allow us to change the behavior of a table.
b.Each table in Lua may have its own metatable.
c.Lua always create new tables without metatables.
d.use setmetatable to set or change the metatable of any table
e.Any table can be the metatable of any other table.
f.A group of related tables may share a common meta.
g.A table can be its own metatable.
h.__add: +
__mul: *
__sub: -
__div: /
__unm: 取负
__pow: 次方
__concat: ..
__eq: equality
__lt: less than
__le: less or equal
__tostring
__metatable
__index
__newindex
i:If the first value has a metatable with an __add field, Lua uses this value as the metamethod, independently of the second value; (2) otherwise, if the second value has a metatable with an __add field, Lua uses this value as the metamethod; (3) otherwise, Lua raises an error.
4.将light user data作为指针使用,并在脚本环境中维护一个以lightuserdata为key的table,value为对应的lua对象,则有,key为C++对象,value为lua对象.
5.userdata本质为一段内存区,在脚本中可作为单一参数进行传递.可为之定义脚本函数以操作该内存,一簇的函数形成一个对象概念,一个内存对象概念.
6.userdata可以有metatable,意味着其可以完成完整的C++对象语义. 检查userdata的metatable(luaL_checkudata)以确保该userdata是所期望的内存对象.
7.Remember that a:size() is equivalent to a.size(a)
8.设置metatable的__index为get方法,__newindex设为set方法,以实现[]的语法语义.
9.设置metatable的__index为metatable自身,并定义get,set,size函数,以实现C++对象语法语义 |
|