[Kde-bindings] Re: Smoke: On classes and objects

Ashley Winters jahqueel at yahoo.com
Mon Apr 4 08:40:38 UTC 2005


--- Luca Fascione <lukes at wetafx.co.nz> wrote:
> Situation:
>  - suppose you have a method:
> 
> void someClass::myMethod (int count, char* string) { /* yadda yadda 
> yadda */ }
> 
>  - which is then overloaded by another method:
> 
> void someClass::myMethod (char* behaviour, int number) { /* re-yadda 
> yadda yadda */ }
> 
>  - it would appear natural to express this in TCL as
> 
> someClass myMethod value1 value2
> 
> Now, suppose that for some reason the actual call is
> 
> someClass myMethod 2 123
> 
> How do you distinguish which function to call?

First, you ask Smoke to return all the methods for someClass which
match the signature 'myMethod$$' (literally, that's the signature of a
method called "myMethod" which accepts 2 value (non-list, non-widget)
arguments). Most of the time (over 90% of the time), there is only one
matching function. You grab that function, ask Smoke what type of
arguments it takes (int,int), and coerce the arguments to that type.

If there's more than one signature returned, you try numerical
conversions: if there's a '.' in the string, try to convert it to a
float. Otherwise, try to convert it to an int. If either succeeds,
check if that exclusively matches one of the signatures Smoke returned.
If so, use that one.

If the conversion to int/float failed, you know a string is being
passed, and you exclude any functions which wanted a number.

In practice, this handles 99% of the functions.

For the remaining 1%, you give up and print out an error message
complaining about an ambiguous function call, so the programmer knows
which 'candidate' functions Smoke had available. You tell them they
need to be explicit and provide a type using [qt int 1] or whatever.

> Man this is nasty... I strongly doubt there is any way to solve
> this...

The code to do what I described above is in PerlQt (and that Ruby one).
It's just a matter of rewriting it for Tcl.

Notice how I made that sound simple? :)

Ashley Winters



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Personals - Better first dates. More second dates. 
http://personals.yahoo.com




More information about the Kde-bindings mailing list