摘要: 有一个函数是这样的:function Car:setSpeed(t_speed) self.speed = t_speed print(self.speed)end我准备调用回调函数的函数:function CarDriver:tapGas(self, callback) currentSpeed = currentSpeed + 10 callback(currentSpeed)end调用过程:CarDriver:tapGas(Car.setSpeed)然后我欢快的调用tapGas,踩着油门踏板。。。结果打印的self.speed = nil......正确的调用过程应该是这样:Ca... 阅读全文
posted @ 2014-04-02 18:00 Mr轨迹 阅读(5081) 评论(0) 推荐(0) 编辑
摘要: metatable是我用Lua语言一段时间都没有搞的很明白的东西。再次遇到,就决心要和metatable叙叙感情。首先谈谈元方法metaFunction有哪些:add, sub, mul, div, mod, pow, unm, concat, len, eq, lt, le, tostring, gc, index, newindex, call...使用的时候记得在元方法前面加上2条下划线:例如:index -> __index说说__index的使用: local t1 = {} function t1.showInfo() print("t1.showInfo Meth 阅读全文
posted @ 2014-04-02 14:00 Mr轨迹 阅读(5044) 评论(0) 推荐(0) 编辑