原创文章,欢迎转载,转载请注明:文章来自[寒江孤叶丶的Cocos2d-x之旅系列]
博客地址:http://blog.csdn.net/qq446569365
在LUA中,重写父类函数之后有时候需要调用父类方法,LUA调用父类方法要比C++中略为复杂一些,如下:
--Test:APUtils.getSuperMethod(self,"setPosition")(self,p) --调用父类方法并传递参数 --获取父类函数 function _G.getSuperMethod(table,methodName) local mt = getmetatable(table) local method = nil while mt and not method do method = mt[methodName] if not method then local index = mt.__index if index and type(index) == "function" then method = index(mt,methodName) elseif index and type(index) == "table" then method = index[methodName] end end mt = getmetatable(mt) end return method end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。