cocos2d-x + lua Custom class

我在MainPageLayer.lua 中定义自己的类 实现如下
@

MainPageLayer = class(“MainPageLayer”)
MainPageLayer.__index = MainPageLayer
function MainPageLayer:init()
— do my init
end
function MainPageLayer:run()
— do my init
end
function MainPageLayer.create()
> local layer = CCLayer:create()
> local t = tolua.getpeer(layer)
> if not t then
> t = {}
> tolua.setpeer(layer, t)
> end
> setmetatable(t, MainPageLayer)
> if nil ~= layer then
> layer:init()
> end
> return layer
end
In theclass () method is to borrow testLua Demo extern.lua Methods
In another file. Lua in a function

local mainPageLayer = MainPageLayer.create()
print(“MainPageLayer.create() type …”…type(mainPageLayer)) — print is userdata type
mainPageLayer:setTag(nTagMainPageLayer) — nTagMainPageLayer = 10000
then mainPageLayer added to the layer

— mainPageLayer:run() — 不报错
in another function in this file call statements

local child = mainMenuMultiplexLayer:getChildByTag(nTagMainPageLayer)
print(“child type …”…type(child)) — 打出的是userdata
print (“child tag …”…child:getTag()) — 打出的是10000
if nil ~= child then
> local mainPage = tolua.cast(child, “MainPageLayer”)
> print(“mainPage type …”…type(mainPage) — print is string type
> mainPage:run() —- error: tip: run is nil .
end

Why types of mainPage is string, and should not be MainPageLayer. because The create () is the userdata type.
Members of the class also cannot call the function.
Is my custom class is there a problem?
Thank you for your advice!

Same problem here I have no Idea what it is someone help us out too please thanks. - Rabbi Binyomin Lisbon

I had know what is my wrong MainPageLayer’s type is table, no userdata,

end