lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I still don't quite believe how well this is going. I've made great inroads integrating Lua and my C++ object model. However, I have one small point where, while the code works, I'm not quite happy with my solution: I have a C++ class UKFrame that displays an image, and I have a specialisation of this C++ class, UKTextFrame, whose image is a rendered text string. Currently, they're exported to Lua as two entirely separate classes. This has the downside that one other method's addFrame() method has to explicitly use luaL_checkudata() twice to find out whether one of its parameters is a UKTextFrame or a UKFrame, so it can treat them the same. (This works for now, but in the future there may be many more frame types, and I'd like to avoid having to manually "polymorph" all of them)

I'm not quite comfortable with the whole __index and metatable stuff, and how they interact with luaL_checkudata(). Looking at the sources, I get the impression that luaL_checkudata() returns NULL for subclasses of the requested type. Is there a facility to do the equivalent of luaL_checkudata() but also look at metatables higher up? Am I even making sense? Am I mixing up __index and the metatable again?

Do any of you have suggestions on how I should model this sort of polymorphism in Lua?

-- M. Uli Kusterer