From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.ams3.giganews.com!border1.nntp.ams2.giganews.com!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!multikabel.net!newsfeed20.multikabel.net!news.glorb.com!news.netfront.net!not-for-mail From: Tarek Ghaleb Newsgroups: comp.lang.ada Subject: Re: System.Address to Access to function/procedure conversion Date: Sun, 28 Jul 2013 22:03:39 +0000 (UTC) Organization: Netfront http://www.netfront.net/ Message-ID: References: <15i0rfwzpj7cy$.ob5l4ffr5iqa$.dlg@40tude.net> NNTP-Posting-Host: 77.247.181.165 X-Trace: adenine.netfront.net 1375049019 49277 77.247.181.165 (28 Jul 2013 22:03:39 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Sun, 28 Jul 2013 22:03:39 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) X-Original-Bytes: 3370 Xref: number.nntp.dca.giganews.com comp.lang.ada:182750 Date: 2013-07-28T22:03:39+00:00 List-Id: On 2013-07-28, Simon Wright wrote: > Tarek Ghaleb 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 ---