Skip to content

Instantly share code, notes, and snippets.

@NoCheroot
Forked from egbulmer/struct-by-value.ss
Created May 12, 2018 18:52
Show Gist options
  • Select an option

  • Save NoCheroot/f084c0e38cb105d362991c9e3ca71ecd to your computer and use it in GitHub Desktop.

Select an option

Save NoCheroot/f084c0e38cb105d362991c9e3ca71ecd to your computer and use it in GitHub Desktop.
Chez Scheme FFI - Structs returned by value
(load-shared-object "./libsbv.so")
(define-ftype color
(struct
[r float]
[g float]
[b float]
[a float]))
(define make-rgba
(foreign-procedure "make_rgba" (float float float float) color))
;; => invalid (non-base) foreign-procedure result ftype color
/* -*- compile-command: "gcc -c -Wall -Werror -fpic -o sbv.o struct_by_value.c; and gcc -shared -o libsbv.so sbv.o"; -*- */
struct color {
float r;
float g;
float b;
float a;
};
struct color from_rgba(float r, float g, float b, float a) {
struct color c;
c.r = r;
c.g = g;
c.b = b;
c.a = a;
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment