chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] Basic FFI Principle in Chicken


From: Chris Mueller
Subject: [Chicken-users] Basic FFI Principle in Chicken
Date: Fri, 06 Sep 2013 08:52:08 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130806 Thunderbird/17.0.8

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



reply via email to

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