lua-users home
lua-l archive

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


Hi List,
I'm a bit stuck at the class C++ problem of getting a pointer to the
base class pointer of a multiply inheriting C++ object.

example

class A{};
class B{};
class C : A, B{};

If I make a userdata for A, B, and C where I used the boxed pointer
method, what's a working strategy for getting a B* from a boxed C*?
When the call to __index comes, I am essentially given a void*, which
in actuality is a C**.  Let's say I'm calling a function defined in
B's userdata class such that I want the C** to become a B*.  AFAICT,
there's no way to do this properly and efficiently without encoding
the byte offset of a B* as compared to a C*, but that is totally
unportable.  I've thought about using some kind of functor mechanism,
but that still requires type info that I don't have.  I guess I could
allocate an object and perform the casts, calculate the offsets and
store those, but it seems like hackery and I would like to avoid it.

Any ideas?

thanks,
wes