How does lua object inherit from CClayer?

I want to let lua object inherit from cocos2dx c++ class,is it possible?
I can imagine the implementation may be like the following codes.

LMap. = {}

function LMap:new
inst = {}
setmetatable(inst, self)
self.index = self
setmetatable(self, CCLayer)
CClayer:index = CClayer
return inst
end

if it is possible, what is the right implementation? your help would be appreciated.

cocos2d-x use tolua*+ to export lua interface, for every c*+ object exist in lua is userdata, in lua 5.1 userdata can associate a private table call “environment”, tolua++ use this feature to store data for every object. when you index the object, it will find in “environment” first. so you can inhrit like this
@

—define class LMap
LMap={}
LMap.__index=LMap
function LMap:printf()
printf(“Lmap Printf”)
end
—create layer object
layer=CCLayer::create()
—let layer inherit LMap
local t=tolua.getpeer(layer) — get environment table
if not t then
t ={}
end
setmetable(t,LMap) — enviroment tabel inherit Lmap
tolua.setpeer(layer,t) — set environment table
—call LMap method
layer:printf() — output is : Lmap Printf
@

a bit boring to implement, this is the best way i find.

funA = class(“funcA”,
function()
return CCLayer:create()
end
})

funcA.__index = funcA

i think this is what you want