I have a library functions defined like that in my C code :
static const struct luaL_reg SelSurfaceLib [] = {
{"CapabilityConst", CapabilityConst},
{"create", createsurface},
{NULL, NULL}
};
static const struct luaL_reg SelSurfaceM [] = {
{"Release", SurfaceRelease},
{"GetPosition", SurfaceGetPosition},
{"clone", SurfaceClone},
{"restore", SurfaceRestore},
{NULL, NULL}
};
void _include_SelSurface( lua_State *L ){
luaL_newmetatable(L, "SelSurface");
lua_pushstring(L, "__index");
lua_pushvalue(L, -2);
lua_settable(L, -3); /* metatable.__index = metatable */
luaL_register(L, NULL, SelSurfaceM);
luaL_register(L,"SelSurface", SelSurfaceLib);
}
And I can use it with this Lua code :
local sub = SelSurface.create()
local x,y = sub:GetPosition()
...
Now, my difficult issue : I'm using follwing code
function HLSubSurface(parent_surface, x,y,sx,sy )
local self = {}
-- fields
local srf = parent_surface:SubSurface( x,y, sx,sy )
-- methods
local meta = {
__index = function (t,k)
local tbl = getmetatable(srf)
return tbl[k]
end
}
setmetatable( self, meta )
return self
end
and my main code is :
sub = HLSubSurface( parent, 0,0, 160,320 )
x,y = sub.GetPosition()
but it's failing
./HDB/80_LeftBar.lua:19: bad argument #1 to 'SetFont' (SelSurface expected, got userdata)
It's because I need to provide srf as 1st argument to GetPosition() function ... but I strictly duno how to do that :(
I don't want to do it when calling GetPosition(), x,y = sub.GetPosition() but I'm looking for a way to do it transparently by setting it in meta's function.
In other words, I would like to have HLSubSurface object to inherit methods from SubSurface.
Any idea ?
Thanks.
Laurent