Guile Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
New smob interface
Mikael Djurfeldt writes:
>
> This is how the naive user does it:
>
> typedef struct my_type_t {
> int a;
> int b;
> } my_type_t;
>
> #define MY_TYPE_A(x) (((my_type_t *) SCM_SMOB_DATA (x))->a)
> #define MY_TYPE_B(x) (((my_type_t *) SCM_SMOB_DATA (x))->b)
>
> long my_type = scm_make_smob_type ("my-type", sizeof (my_type_t));
>
> SCM
> scm_make_my_type (int a, int b)
> {
> SCM z = scm_make_smob (my_type);
> MY_TYPE_A (z) = a;
> MY_TYPE_B (z) = b;
> return z;
> }
>
> Just as before, the advanced user can write his own versions of the
> mark, free, print, and, equalp functions:
>
> scm_set_smob_mark (my_type, my_mark);
> scm_set_smob_free (my_type, my_free);
> etc.
>
Would the following work for a wrapper for the ncurses library:
long WINDOW_type = scm_make_smob_type ("WINDOW_type", sizeof (WINDOW));
#define SCM2WINDOW (x) ((WINDOW *)SCM_SMOB_DATA)
scm_size_t WINDOW_free (SCM object)
{
WINDOW *w;
w = SCM2WINDOW (object);
gh_defer_ints ();
delwin (w);
gh_allow_ints ();
return sizeof (WINDOW);
}
scm_set_smob_free (WINDOW_type, &WINDOW_free);
SCM WINDOW2SCM (WINDOW *w)
{
SCM z;
SCM_NEWSMOB (z, WINDOW_type, w);
return z;
}
Or does the fact that windows may contain pointers to other windows which
are subject to guile's memory administration make it impossible to use
scm_make_smob?
Guile Home |
Main Index |
Thread Index