guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Custom foreign types


From: Maxime Devos
Subject: RE: Custom foreign types
Date: Thu, 20 Jun 2024 00:16:43 +0200

>Hello, all.

>I know we can create pointers to structs with make-c-struct, but I would
like to pass structs directly as arguments to foreign functions. I can do
that by using bytevector-uint-ref, and setting the size to that of the
struct, but when it is time to specify the type in pointer->procedure, I am
out of luck if the sizes don't match.

Instead of searching for a type of the same size of the struct, why not pass 
the struct type and struct directly to Guile? From the manual:
>One may also pass structs as values, passing structs as foreign pointers. See 
>Foreign Structs, for more information on how to express struct types and 
>struct values.
I’m not really clear on what the precise API is for setting struct arguments 
and whether I interpreted that sentence correctly(*), but ...

> Is there a cleaner way to do this?

... I think the answer is ‘yes’ , though I don’t know what this cleaner way is.
You may want to look at the implementation for clarity (and if you find the 
answer, an addition to the manual would be appreciated).

Best regards,
Maxime Devos.

(*) I think what it means is that as type you set (list this-field-type 
that-field-type ...) and as ‘Scheme value’ you set a foreign pointer that 
contains the struct. If it doesn’t mean that, you could try letting the value 
be (list this-field-value that-field-value ...).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]