librelist archives

« back to archive

C wrappers: how to set a function pointer?

C wrappers: how to set a function pointer?

From:
Cyril Adrian
Date:
2012-05-20 @ 07:04
Hi all, Paolo,

I need to use GNU readline with some of its extended possibilities, viz.
the completion fonction (rl_attempted_completion_function).

My question is, how do I set that function pointer?

Thanks,

*Cyril ADRIAN*
*http://www.cadrian.net/cyril*
[image: Facebook] <https://www.facebook.com/cyril.adrian> [image:
Twitter]<https://twitter.com/cadbart> [image:
LinkedIn] <http://fr.linkedin.com/in/cadrian> [image: Google
Plus]<https://plus.google.com/100388810006463519079/posts> [image:
Google 
Calendar]<https://www.google.com/calendar/embed?src=1t93vvvrdc26ee0f83p0cunj60%40group.calendar.google.com&ctz=Europe/Paris>
Contact me: [image: Google Talk] cyril.adrian@gmail.com
 [image: Twitter] <http://twitter.com/cadbart> Latest tweet: [Liberty]
http://t.co/ZsEJpONC Cyril Adrian - added generation management to
HISTORY_ITERATOR
Follow @cadbart <http://twitter.com/cadbart> Reply

<http://twitter.com/?status=@cadbart%20&in_reply_to_status_id=203384281979027460&in_reply_to=cadbart>
Retweet

<http://twitter.com/?status=RT%20%40cadbart%3A%20%5BLiberty%5D%20http%3A%2F%2Ft.co%2FZsEJpONC%20Cyril%20Adrian%20-%20added%20generation%20management%20to%20HISTORY_ITERATOR>
 09:19 May-18<http://twitter.com/cadbart/statuses/203384281979027456>
  Get this email app!

<http://www.wisestamp.com/apps/twitter?utm_source=extension&utm_medium=email&utm_term=twitter&utm_campaign=apps>

 [image: Google Plus] <http://plus.google.com/100388810006463519079> My
latest G+: Prochains concerts de Contraste : Victor Hugo et la Musiqueen
partenariat avec l'Orchestre Besançon-Montbéliard Franche-Comté - vendredi
10/02 (Kursaal, Besançon, 20h00) - samedi 11/02 (MA scène nationale,
Montbéliard, 20h00) - dimanche 12/02
(Sa...<http://plus.google.com/100388810006463519079/posts/Nozsd4fh2M4/>
My G+ <http://plus.google.com/100388810006463519079> -
Posts<http://plus.google.com/100388810006463519079/posts/>- Add
to Circles <http://plus.google.com/100388810006463519079/about/> - 13:31
Feb-09 <http://plus.google.com/100388810006463519079>
  Get this email app!

<http://www.wisestamp.com/apps/plus?utm_source=extension&utm_medium=email&utm_term=plus&utm_campaign=apps>

[image: My QR VCard]
  Get a signature like this.

<http://r1.wisestamp.com/r/landing?promo=17&dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_17>
CLICK

HERE.<http://r1.wisestamp.com/r/landing?promo=17&dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_17>

Re: [libertyeiffel] C wrappers: how to set a function pointer?

From:
Paolo Redaelli
Date:
2012-05-21 @ 09:17
Il 20/05/2012 09:04, Cyril ADRIAN ha scritto:
> Hi all, Paolo,
>
> I need to use GNU readline with some of its extended possibilities, 
> viz. the completion fonction (rl_attempted_completion_function).
>
> My question is, how do I set that function pointer?
You coulnd't so I added this feature to wrappers generator (see commit 

https://github.com/tybor/Liberty/commit/96c83a9e73e54b1100f0d4c44d39292a14ef775c).

Now for each global variable foo you get a set_foo feature (oh, is just 
a oneliner).  So you will find set_rl_attempted_completion_function 
intoREADLINE_EXTERNAL after recompiling wrappers-generator and running 
it again on readlin.
Sorry for the late answer. I wish I could provide you a full scale 
callback support but I hit a subtle bug in the compiler. I discovered that
foo (a: STRING; b,c: INTEGER_32) is -- $foo is ok
foo (a: LINKED_LIST[POINTER]; b,c: INTEGER_32) is -- $foo is ok
foo (a: LINKED_LIST[POINTER]; b,c: INTEGER_32) is -- $foo is ok
foo (a: NATIVE_ARRAY[CHARACTER]; b,c: INTEGER_32) is -- $foo is ok
foo (a: NATIVE_ARRAY[POINTER]; b,c: INTEGER_32) is -- $foo crashes the 
compiler

I'm sure you are more aware than me of all the details of interfacing 
with C; just let me know if you want me to write a more proper 
Eiffel-like wrapper to therl_attempted_completion_function for example 
attempted_completion (a_string: ABSTRACT_STRING||; a_start, an_end: 
INTEGER_32): ITERABLE[ABSTRACT_STRING]
I'm porting my monodes from Qt/C++ to JavaScript/HTML5 canvas in order 
to learn Javascript a little..... so that I may write a more direct js 
backend... I liked to provide Liberty wrappers to HTML5/Canvas features 
but I discovered the way EMscripten generates code makes this a little 
too convoluted for me... basically they map SDL and X to canvas....

Re: [libertyeiffel] C wrappers: how to set a function pointer?

From:
Cyril Adrian
Date:
2012-05-21 @ 09:29
Hi Paolo,

2012/5/21 Paolo Redaelli <paolo.redaelli@gmail.com>

> You coulnd't so I added this feature to wrappers generator (see commit
> 
https://github.com/tybor/Liberty/commit/96c83a9e73e54b1100f0d4c44d39292a14ef775c).
> Now for each global variable foo you get a set_foo feature (oh, is just a
> oneliner).  So you will find set_rl_attempted_completion_function 
intoREADLINE_EXTERNAL after
> recompiling wrappers-generator and running it again on readlin.
>

great :-) but I'm afraid that's not enough because as you found out it
wants a pointer to a C function. I prefer adding some C glue (i.e. a C
function that calls Eiffel back via CECIL).


> Sorry for the late answer. I wish I could provide you a full scale
> callback support but I hit a subtle bug in the compiler. I discovered that
> foo (a: STRING; b,c: INTEGER_32) is -- $foo is ok
> foo (a: LINKED_LIST[POINTER]; b,c: INTEGER_32) is -- $foo is ok
> foo (a: LINKED_LIST[POINTER]; b,c: INTEGER_32) is -- $foo is ok
> foo (a: NATIVE_ARRAY[CHARACTER]; b,c: INTEGER_32) is -- $foo is ok
> foo (a: NATIVE_ARRAY[POINTER]; b,c: INTEGER_32) is -- $foo crashes the
> compiler
>

ouch :-/



> I'm sure you are more aware than me of all the details of interfacing with
> C; just let me know if you want me to write a more proper Eiffel-like
> wrapper to the rl_attempted_completion_function for example
> attempted_completion (a_string: ABSTRACT_STRING; a_start, an_end:
> INTEGER_32): ITERABLE[ABSTRACT_STRING]
>

Yes, that's my target. Because I needed asap, I was hand-writing the
low-level C glue and the upper level features (in READ_LINE), I'll commit
my code as an example so you can work from that :-)



> I'm porting my monodes from Qt/C++ to JavaScript/HTML5 canvas in order to
> learn Javascript a little..... so that I may write a more direct js
> backend... I liked to provide Liberty wrappers to HTML5/Canvas features but
> I discovered the way EMscripten generates code makes this a little too
> convoluted for me... basically they map SDL and X to canvas....
>
On my side, still working on pwd (https://github.com/cadrian/pwd), that's
why I need a good readline support.

Cheers

 *Cyril ADRIAN* *(from office)*
http://www.cadrian.net/cyril
[image: Twitter] <http://twitter.com/cadbart> [image:
LinkedIn]<http://fr.linkedin.com/in/cadrian> [image:
Google Plus] <https://plus.google.com/u/0/100388810006463519079/> [image:
Google 
Calendar]<https://www.google.com/calendar/embed?src=1t93vvvrdc26ee0f83p0cunj60%40group.calendar.google.com&ctz=Europe/Paris>
Contact me: [image: Google Talk] cyril.adrian@gmail.com
 [image: Twitter] <http://twitter.com/cadbart> Latest tweet: [Liberty]
http://t.co/ZsEJpONC Cyril Adrian - added generation management to
HISTORY_ITERATOR
Follow @cadbart <http://twitter.com/cadbart> Reply

<http://twitter.com/?status=@cadbart%20&in_reply_to_status_id=203384281979027460&in_reply_to=cadbart>
Retweet

<http://twitter.com/?status=RT%20%40cadbart%3A%20%5BLiberty%5D%20http%3A%2F%2Ft.co%2FZsEJpONC%20Cyril%20Adrian%20-%20added%20generation%20management%20to%20HISTORY_ITERATOR>
 09:19 May-18<http://twitter.com/cadbart/statuses/203384281979027456>
  Get this email app!

<http://www.wisestamp.com/apps/twitter?utm_source=extension&utm_medium=email&utm_term=twitter&utm_campaign=apps>

 [image: Google Plus] <http://plus.google.com/100388810006463519079> My
latest G+: Prochains concerts de Contraste : Victor Hugo et la Musiqueen
partenariat avec l'Orchestre Besançon-Montbéliard Franche-Comté - vendredi
10/02 (Kursaal, Besançon, 20h00) - samedi 11/02 (MA scène nationale,
Montbéliard, 20h00) - dimanche 12/02
(Sa...<http://plus.google.com/100388810006463519079/posts/Nozsd4fh2M4/>
My G+ <http://plus.google.com/100388810006463519079> -
Posts<http://plus.google.com/100388810006463519079/posts/>- Add
to Circles <http://plus.google.com/100388810006463519079/about/> - 13:31
Feb-09 <http://plus.google.com/100388810006463519079>
  Get this email app!

<http://www.wisestamp.com/apps/plus?utm_source=extension&utm_medium=email&utm_term=plus&utm_campaign=apps>

  <http://www.linkedin.com/in/cyril.adrian>
  Want a signature like mine?

<http://r1.wisestamp.com/r/landing?promo=22&dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_22>
Click

here.<http://r1.wisestamp.com/r/landing?promo=22&dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_22>