[Kde-bindings] Get a pointer to SmokeBinding

Arno Rehn arno at arnorehn.de
Tue Jan 15 14:28:57 UTC 2013


On 15/01/13 00:19, j j wrote:
>> But if there's a valid use-case I wouldn't object to implementing this in
> smokev4.
>
> I'm only learning to use Smoke, so maybe what I want to do can be achieved
> in some other way. I wan't to be able to call the most derived method given
> a Smoke object.
>
> Say I have a Smoke object foo of type Foo, on which I have set a
> SmokeBinding bind which overrides bar(). Now say I call foo's method bar()
> thorugh the Smoke api. It seems that this results in Foo.bar being called
> directly, without bind->callMethod() being called first. I could call the
> most derived method if I could get to the binding instance, but if there's
> a better way to do it, I'd love to hear about it.
I see. This will be supported in smokev4, but not the current Smoke.
Currently we assume that if you create a smoke object, the target 
language takes care of virtual method resulution and if you call a 
virtual method through the Smoke API, you really want to call the 
original C++ method.

Now you could do some nasty pointer arithmetic for the time being. The 
SmokeBinding* pointer is simply appended to the original class and we 
have size information in Smoke. So something like this could work:

char *ptr = reinterpret_cast<char*>(smokeObject) + smokeClass->size;
SmokeBinding *bind = *reinterpret_cast<SmokeBinding**>(ptr);

Note that this is probably undefined behaviour per se ;)

What are you doing with Smoke? I'm interested in every project using it :)

-- 
Arno Rehn


More information about the Kde-bindings mailing list