From: Tarek Ghaleb <invalid@invalid.org>
Subject: Re: System.Address to Access to function/procedure conversion
Date: Sun, 28 Jul 2013 22:03:39 +0000 (UTC)
Date: 2013-07-28T22:03:39+00:00 [thread overview]
Message-ID: <kt44fp$1g3t$1@adenine.netfront.net> (raw)
In-Reply-To: ly7ggasd3w.fsf@pushface.org
On 2013-07-28, Simon Wright <simon@pushface.org> wrote:
> Tarek Ghaleb <invalid@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
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
next prev parent reply other threads:[~2013-07-28 22:03 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-28 15:27 System.Address to Access to function/procedure conversion Tarek Ghaleb
2013-07-28 16:14 ` Dmitry A. Kazakov
2013-07-28 19:05 ` Tarek Ghaleb
2013-07-28 19:23 ` Simon Wright
2013-07-28 22:03 ` Tarek Ghaleb [this message]
2013-07-28 20:03 ` Dmitry A. Kazakov
2013-07-28 21:13 ` Shark8
2013-07-28 22:54 ` Tarek Ghaleb
2013-07-29 3:27 ` Shark8
2013-07-29 7:06 ` Tarek Ghaleb
2013-07-28 17:19 ` Jeffrey Carter
2013-07-28 19:05 ` Tarek Ghaleb
2013-07-28 20:04 ` Jeffrey Carter
2013-07-28 21:31 ` Maciej Sobczak
2013-07-29 6:26 ` Tarek Ghaleb
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox