use the way of extern.lua in TestLua Demo : function class(className, super) to create my Class.
the code as:
— 创建层
@
local CardListLayer = class(“CardListLayer”)
CardListLayer.__index = CardListLayer
function CardListLayer.extend(target)
local t = tolua.getpeer(target)
if not t then
t = {}
tolua.setpeer(target, t)
end
setmetatable(t, CardListLayer)
return target
end
— overwrite
function CardListLayer:init()
— do samething my init()
return true
end
function CardListLayer.create()
local layer = CardListLayer.extend(CCLayer:create())
if nil ~= layer then
layer:init()
end
return layer
end
return CardListLayer
@
in other ScriptFile create object of my class and call
local pLayer = require(“CardListLayer.lua”) — CardListLayer.lua my Class
local cardListLayer = pLayer:create()
print(type(cardListLayer))
this.layer.addChild(cardListLayer)
local cardListLayer = pLayer:create() type is userdata
this.layer.addChild(cardListLayer) error :error in function ‘addChild’.
argument #2 is ‘[no object]’; ‘CCNode’ expected .
why?
some question in my class ?