[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Use of define-foreign-record
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] Use of define-foreign-record |
Date: |
Wed, 15 Dec 2004 07:34:20 +0100 |
On Tue, 14 Dec 2004 17:59:24 -0600, Ariel Rios <address@hidden> wrote:
> Hello,
>
> Which is the way of adding C struct definitions?
>
> Let's say I have defined the following:
>
> //something.h
>
> struct _something
> {
> _foo foo;
>
> char *title;
> int index;
>
> };
>
> Then on my scm file what do I put?
>
> (define-foreing-record ...)
>
You can do something along these lines:
#>
typedef void *_foo; /* just defined, so the example works. */
struct _something
{
_foo foo;
char *title;
int index;
};
<#
#>!
/* define-foreign-record does not define any allocator: */
static struct _something *make_something(char *name, int index)
{
struct _something *s = (struct _something *)malloc(sizeof(struct _something));
s->title = strdup(name);
s->index = index;
return s;
}
static void free_something(struct _something *s)
{
free(s->title);
free(s);
}
<#
(define-foreign-record _something
(c-string title)
(int index) )
(define s1 (make_something "abc" 123))
(print (_something-title s1))
(print (_something-index s1))
(free_something s1)
cheers,
felix