On 2013-07-28, Simon Wright <
si...@pushface.org> wrote:
> Tarek Ghaleb <
inv...@invalid.org> writes:
>
>> Ideally, Callback() is not the actual imported callback() but it takes
>> Ada friendly parameters and does any type conversions needed then
>> calls the imported callback() function.
>
> I find this confusing because I'm used to thinking of the procedure-to-
> be-called-back as the 'callback', and what you're talking about here is
> the registration interface. But if that's FLTK's nomenclature ...
Yes, this is the naming for FLTK, but I can change that I guess. I
probably should have used a different name here for clarity, Register()
perhaps or Register_Callback().
> Especially if the called-back procedure takes parameters, you're going
> to have to do a conversion on the way back as well!
Initially, I thought it was simple, but now it doesn't seem so easy
:-) I'd want to wrap the user callback, Button_Cb() for example, in
another procedure that fits the profile required by the imported
callback registration function and does that conversion and calling of
Button_Cb().
One idea of the Registration procedure, stripped down and not
considering parameters and parameter conversion (but saves the user
from having to use pragma Convention C) is
procedure Register_Callback (Proc : access procedure) is
procedure Cb_Wrapper;
pragma Convention (C, Cb_Wrapper);
procedure Cb_Wrapper is
begin
Proc.all;
end Cb_Wrapper;
begin
imported_callback_registration (Cb_Wrapper'Access);
end Register_Callback;
But this of course wouldn't work, since the Wrapper is allocated on
the stack and is deeper than access type.
> I think you might be able to do something with a generic, but .. you
> can't make a generic formal type definition that declares an "access
> to procedure with this parameter profile" type.
A generic used in which way? I'd like Register_Callback() to be
callable simply with an access to a procedure that fits a certain
profile with the caller not having to worry about details. The wrapper
could be a generic maybe. There are a couple of other ideas but
nothing promising so far.
Tarek.
--
The opposite of a correct statement is a false statement. But the opposite
of a profound truth may well be another profound truth. -- Niels Bohr