2014年7月8日
摘要: 理解Lua语言中的__index,__newindex,rawget和rawset在谈及Lua中的__index,__newindex,rawget和rawset前,需要理解Lua中的元表这个概念。零、元表的概念对Lua中元表的解释: 元表可以改变表的行为模式。这里举个例子:Window = {}W... 阅读全文
posted @ 2014-07-08 11:38 chenhanqing_blcu 阅读(447) 评论(0) 推荐(0) 编辑
摘要: 相信接触过ios开发的人来说对NSNotificationCenter都不陌生。而在cocos2d-x中也参照这个类,提供了CCNotificationCenter这个类,用作通知中心。而我主要是使用NotificationCenter 进行不同类之间的参数传递。(譬如说在两个layer之间进行参... 阅读全文
posted @ 2014-07-08 11:37 chenhanqing_blcu 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 赋值是改变一个变量的值和改变表域的最基本的方法。a = "hello" .. "world"t.n = t.n + 1Lua可以对多个变量同时赋值,变量列表和值列表的各个元素用逗号分开,赋值语句右边的值会依次赋给左边的变量。a, b = 10, 2*x a=10; b=2*x遇到赋值语句Lua会先... 阅读全文
posted @ 2014-07-08 11:36 chenhanqing_blcu 阅读(350) 评论(0) 推荐(0) 编辑
摘要: local layer = getBaseLayer()sprite = CCSprite:create("Images/white-512x512.png") layer:addChild(sprite, 0, 40) sprite:setPosition(CCPointMake(s.width ... 阅读全文
posted @ 2014-07-08 11:35 chenhanqing_blcu 阅读(164) 评论(0) 推荐(0) 编辑
摘要: Lua是动态类型语言,变量不要类型定义。Lua中有8个基本类型分别为:nil、boolean、number、string、userdata、function、thread和table。函数type可以测试给定变量或者值 的类型。print(type("Hello world"))print(type... 阅读全文
posted @ 2014-07-08 11:33 chenhanqing_blcu 阅读(174) 评论(0) 推荐(0) 编辑
摘要: --page = [[------An HTML Page------Lua--[a text between double brackets]------]]--io.write(page)--print("19"+1)--print(10 .. 10)-- .. 字符串连接符--line=io... 阅读全文
posted @ 2014-07-08 11:33 chenhanqing_blcu 阅读(133) 评论(0) 推荐(0) 编辑
摘要: Chunks是一系列语句,Lua执行的每一块语句,比如一个文件或者交互模式下的每一行都是一个Chunks每个语句结尾的分号(;)是可选的,但如果同一行有多个语句最好用;假定一个文件a内有单个语句x=1;另一个文件b有语句print(x)prompt> lua -la -lb将在一个 Chunk 内... 阅读全文
posted @ 2014-07-08 11:32 chenhanqing_blcu 阅读(367) 评论(0) 推荐(0) 编辑