* interfacing C and guile
@ 2022-12-30 9:36 Damien Mattei
2022-12-30 13:48 ` Damien Mattei
0 siblings, 1 reply; 4+ messages in thread
From: Damien Mattei @ 2022-12-30 9:36 UTC (permalink / raw)
To: guile-user
hi,
how do i declare in Guile a function that in C is of this type:
int foo(int,int,char *)
the problem i have is with the char *:
(define cfunc (foreign-library-function "libguile-cfunc" "openmp"
#:return-type int #:arg-types (list int int ????)))
i do not know what to put in place of ????
Regards,
Damien
note: what if const char* ? (not sure i need it)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: interfacing C and guile
2022-12-30 9:36 interfacing C and guile Damien Mattei
@ 2022-12-30 13:48 ` Damien Mattei
2022-12-30 16:03 ` Olivier Dion via General Guile related discussions
0 siblings, 1 reply; 4+ messages in thread
From: Damien Mattei @ 2022-12-30 13:48 UTC (permalink / raw)
To: guile-user
there was a mistake in my previous post, i wanted to say int cfunc
(int,int,char *), suggestion answered to use '*:
(define cfunc (foreign-library-function "libguile-cfunc" "cfunc"
#:return-type int #:arg-types (list int int '*)))
works at this step but gives an error later:
(cfunc 3 27 "toto")
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
In procedure foreign-call: Wrong type argument in position 1 (expecting
POINTER_P): "toto"
On Fri, Dec 30, 2022 at 10:36 AM Damien Mattei <damien.mattei@gmail.com>
wrote:
> hi,
> how do i declare in Guile a function that in C is of this type:
> int foo(int,int,char *)
> the problem i have is with the char *:
> (define cfunc (foreign-library-function "libguile-cfunc" "openmp"
> #:return-type int #:arg-types (list int int ????)))
> i do not know what to put in place of ????
>
> Regards,
> Damien
>
> note: what if const char* ? (not sure i need it)
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: interfacing C and guile
2022-12-30 13:48 ` Damien Mattei
@ 2022-12-30 16:03 ` Olivier Dion via General Guile related discussions
2022-12-30 16:52 ` Damien Mattei
0 siblings, 1 reply; 4+ messages in thread
From: Olivier Dion via General Guile related discussions @ 2022-12-30 16:03 UTC (permalink / raw)
To: Damien Mattei, guile-user
On Fri, 30 Dec 2022, Damien Mattei <damien.mattei@gmail.com> wrote:
> there was a mistake in my previous post, i wanted to say int cfunc
> (int,int,char *), suggestion answered to use '*:
>
> (define cfunc (foreign-library-function "libguile-cfunc" "cfunc"
> #:return-type int #:arg-types (list int int '*)))
>
> works at this step but gives an error later:
>
> (cfunc 3 27 "toto")
> ice-9/boot-9.scm:1685:16: In procedure raise-exception:
> In procedure foreign-call: Wrong type argument in position 1 (expecting
> POINTER_P): "toto"
Try (cfunc 3 27 (string->pointer "toto")). It's available in the module
(system foreign).
--
Olivier Dion
oldiob.dev
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: interfacing C and guile
2022-12-30 16:03 ` Olivier Dion via General Guile related discussions
@ 2022-12-30 16:52 ` Damien Mattei
0 siblings, 0 replies; 4+ messages in thread
From: Damien Mattei @ 2022-12-30 16:52 UTC (permalink / raw)
To: guile-user
yes Olivier, i already found this solution a few hours ago digging in the
Guile doc:
https://www.gnu.org/software/guile/manual/html_node/Void-Pointers-and-Byte-Access.html
thanks
Damien
On Fri, Dec 30, 2022 at 5:03 PM Olivier Dion <olivier.dion@polymtl.ca>
wrote:
> On Fri, 30 Dec 2022, Damien Mattei <damien.mattei@gmail.com> wrote:
> > there was a mistake in my previous post, i wanted to say int cfunc
> > (int,int,char *), suggestion answered to use '*:
> >
> > (define cfunc (foreign-library-function "libguile-cfunc" "cfunc"
> > #:return-type int #:arg-types (list int int '*)))
> >
> > works at this step but gives an error later:
> >
> > (cfunc 3 27 "toto")
> > ice-9/boot-9.scm:1685:16: In procedure raise-exception:
> > In procedure foreign-call: Wrong type argument in position 1 (expecting
> > POINTER_P): "toto"
>
> Try (cfunc 3 27 (string->pointer "toto")). It's available in the module
> (system foreign).
>
> --
> Olivier Dion
> oldiob.dev
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-12-30 16:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-30 9:36 interfacing C and guile Damien Mattei
2022-12-30 13:48 ` Damien Mattei
2022-12-30 16:03 ` Olivier Dion via General Guile related discussions
2022-12-30 16:52 ` Damien Mattei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).