Hi,

i've currently started experimenting with the FFI interface provided by the chicken compiler and have some principle questions about its common usage.

Assume the given C Code:

struct color {
  int red;
  int green;
  int blue;
  int alpha;
};

struct color* alloc_new_color(int red, int green, int blue, int alpha);

1) How do you interface allocation methods in generell with avoidance of memory leaks?

From the documentation i know, you can write:

(define-foreign-type color* (pointer (struct "color"))))

(define alloc_new_color (foreign-lambda color* "alloc_new_color" integer integer integer integer))

But this expects the user have to free the memory manually.

Is there an uncomplicated way to register some automechanism?


2) How can i solve this problem:

void rgb_to_hsl(struct color* rgb, float* hue, float* sat, float* lum);

This is simple conversation method that uses multiple return values (hue, sat, lum).

How can i write a ffi define that accepts an argument of type "color*"
and returns a scheme-vector with three elements?


Hope its not too basic for you. :)

Chris

_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to