原创文章,欢迎转载,转载请注明:文章来自[寒江孤叶丶的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原文链接:https://www.f2er.com/cocos2dx/342013.html