#lang at-exp racket/base
(require dynamic-ffi/unsafe)
@define-inline-ffi[struct-test]{
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
typedef struct {
char *name;
uint64_t value;
} number;
char* names[] = {"zero", "one", "two", "three", "four", "five", "six"
"seven", "eight", "nine", "ten", "eleven", "twelve"};
number add(number a, number b) {
number c;
c.value = a.value + b.value;
if (c.value >12) {
fprintf(stderr, "error: this example can only count to twelve...\n");
exit(1);
}
c.name = names[c.value];
return c;
}
}
;; _list-structs are created by default. I hope to optimize this in the future.
(define n2 (list "two" 2))
(define n7 (list "seven" 7))
(printf "add(n2, n2): ~a\n" (struct-test 'add n2 n2)) ;; output: add(n2, n2): (four 4)
(printf "add(n7, n7): ~a\n" (struct-test 'add n7 n7)) ;; output: error: this example can only count to twelve...
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/eff63a65-d1b7-475b-9240-7158b024d740%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I've recently released a new library for dynamically generating FFI bindings to C by parsing header files.It also allows users to create FFI libraries by writing C functions directly inline in Racket programs.
Thanks, this looks very promising! Even more so with the option of generating static FFIs that I saw in the documentation. That's important in practice to prevent LLVM and clang becoming dependencies for lots of Racket code.
Now if you could also provide a tool for dynamically generating free time for playing with this, I'd be even happier ;-)
Konrad.