From: Daniel S. <dsc...@sc...> - 2011-12-07 21:32:52
|
Suppose I have a class hierarchy like: class XmlNode { public: XmlNode* parent(); XmlNode* firstChild(); XmlNode* nextSibling(); enum Type { TYPE1, TYPE2 }; }; class XmlNodeType1 : public XmlNode { public: int attr1(); }; class XmlNodeType2 : public XmlNode { public: int attr2(); }; Then if I want to traverse through that, I might want to have Lua code something like: if (node:firstChild():type() == mod.XmlNode_TYPE1) then print ("child is type1 node with attr1 = " .. node:firstChild():attr1()) elseif (node:firstChild():type() == mod.XmlNode_TYPE2) then print ("child is type2 node with attr2 = " .. node:firstChild():attr2()) end But that doesn't actually work with the current implementation of Lua bindings (I'm using Swig version 2.0.4). It seems that the wrapper for XmlNode::firstChild() statically assigns the XmlNode metatable to the resulting userdata, instead of looking at the actual return value and figuring out the correct metatable to use. It would be ugly, and IMO contrary to the spirit of Lua, to have to define wrappers for various dynamic_cast<XmlNodeType1*> etc. functions. My question: is this a bug in the Lua binding runtime, or was it a design choice (or an unfortunate design restriction maybe)? -- Daniel |