Hi, On 9 May 2008, at 12:28, Dennis Schridde wrote: > Am Freitag, 9. Mai 2008 12:17:43 schrieb Freddie Witherden: >> On Fri, 9 May 2008 10:38:54 +0200, Dennis Schridde >> <[EMAIL PROTECTED]> >> wrote: >>> Just something I experimented with: >>> #define CALL(OBJECT, METHOD) ((OBJECT)->vtable->METHOD) >>> CALL(xob, xme)(p1, p2); >> >> Currently the way virtual methods (i.e., those which use the >> vtable) are >> called is exactly the same as that of non-virtual methods: >> <className><methodName>, so: wigetSetLayout(...). > So the API will be "C-style"? I somehow assumed it was intended to > provide a > object oriented syntax, i.e. via GET_VTABLE().
The 'user' API will be C-style, yes. So the fact that there is a vtable is completely hidden from the user of an object. >> This is somewhat useful, as in the virtual method functions (e.g. >> widgetDoDraw), which is a pure virtual method, we can ASSERT that >> object->vtable->method is NOT NULL. A macro may complicate this >> somewhat. > So the idea is that there are wrapper functions, like widgetDoDraw > (), which > call widget->vtable->method, which may point to buttonDoDraw()? Exactly. >> It may seem a bit strange, if, in the code we get: >> button *btn = buttonCreate(...); >> widget *root = widgetGetRoot(WIDGET(btn)); >> CALL(btn, setLayout)(...); > Just wanted to mention this, since we talked about that recently. > I got the idea that the above way might work, tested, and it did work. > And since I saw some GET_VTABLE(obj)->method in the code, I thought > I might > also tell you what I tested. WIDGET_GET_VTBL is designed to get the vtable that should be used for calling widget methods. So if sub-classes export their on virtual functions they will also have a FOO_GET_VTBL. It is very important to cast here. As ((widget *) self)->vtbl is different from that of say ((button *) self)->vtbl. The FOO_GET_VTBL methods are designed to make this a bit easier. Regards, Freddie. _______________________________________________ Warzone-dev mailing list Warzone-dev@gna.org https://mail.gna.org/listinfo/warzone-dev