Combining two metatables into one for userdata
Colm Sloan <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
I tried the following function that I believe should work but it doesn't.
--lua
function CombineObjectMetaTables( object1, object2 )
local meta1 = getmetatable( object1 )
local meta2 = getmetatable( object2 )
local metaCombined = { __index = function( t, k )
if (meta1[ k ]) then return meta1[ k ] end
if (meta2[ k ]) then return meta2[ k ] end
--reaches this point, meaning nothing was found
end }
debug.setmetatable( object1, metaCombined ) --set the new meta table
return object1 --return the object with the new metatable
end
//C++
m_LuaObject = luabind::call_function<luabind::object>( L,
"CombineObjectMetaTables", m_LuaObject, this );
luabind::call_member<void>( m_LuaObject, "Spawn" ); //error: attempt to call
method 'Spawn' (a nil value) (though it is a member function of the
particular class I'm trying)
Does it fail because the lua code is wrong or is it because Luabind has a
special way of managing the __index function and changing it will make the
system break? If it does have such a way, how can I do what I'm trying here
without breaking Luabind?
Thanks
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user