[Mono-list] late linking & dynamic invocation ...
Michael Meeks
michael@ximian.com
05 Jul 2002 08:40:18 +0100
Hi Miguel,
On Thu, 2002-07-04 at 21:21, Miguel de Icaza wrote:
> I am having a bit of trouble understanding what the problem is that
> you are trying to solve in the discussion about delegates.
:-) well - there were 2 issues that got rather confused I think.
> For any "callback" function that you might want to call from your
> code, you will need to have a delegate definition
I'm relatively resigned to that.
> this is just part of
> the contract of the signature, so implementors can create methods
> conforming to this definition.
Right [ although this is not really necessary IMHO ].
> > a) declare your method - with signature:
> >
> > void myAllocateHandler (Widget w,
> > Allocation a,
> > Object closure)
> > { ... }
...
> > c) re-type the method signature [ in some mangled form ] in the
> > name of the delegate on connection:
> >
> > object.connect (new FooWidgetAllocationObject
> > (myAllocateHandler));
>
> You do not retype the signature, instead you use the delegate name:
>
> object += new FooWidgetAllocation (myAllocationHandler)
>
> So there are two sides of the problem:
>
> * The "definition" side, which consists of a delegate
> declaration.
>
> * The "user" side, which consists of doing the object +=
> new DelegateName (Function).
Ok - the problem is quite simple. In order to reasonably disambiguate
the 'DelegateName' you need to mangle the types into the delegate name,
in a signal handling system there will be a lot of these, thus:
new DelegateName (fn) -> new DelegateLongIntShortString
(my_long_int_short_string_method);
Do you now see that I typed the signature twice ? [ ok so it takes a
leap of imagination to see that my_long_int_short_string_method is an
arbitrary name for a method of that signature ].
The tragedy of this all is that I don't care at all about the type of
the delegate, and the method I pass it to will instantly discard that
information -> a generic 'Delegate' reference so, doing all this
redundant typing seems a total waste.
In short - I want a way to generically create a Delegate with the right
signature from a method; so that we can then generically invoke it later
[ nicely typed signal emissions ].
In short, it's the tragedy of this:
Delegate *del = new DelegateLongIntShortString
(my_long_int_short_string_method);
I want to be able to do:
Delegate *del = new Delegate (my_long_int_short_string_method);
or better, have an auto-coercion built into the method signature so
that one doesn't have to type "new" anything :-)
Does that make it clearer ? it's not a matter of type safety, but
linguistic style it seems to me [ and possibly compiler simplicity as
well ;-].
Regards,
Michael.
--
mmeeks@gnu.org <><, Pseudo Engineer, itinerant idiot