guile-user
[Top][All Lists]
Advanced

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

Re: how would i wrap this function in guile?


From: Stephen Compall
Subject: Re: how would i wrap this function in guile?
Date: Wed, 19 Jan 2005 17:37:15 -0600

On Wed, 2005-01-19 at 14:57 -0700, Ray Lehtiniemi wrote:
> i have a function in a library that i would like to wrap, but am
> not sure how.
> 
>   int look_up_object (char * name, void **address);
> 
> the idea is to pass a name into this function, and it will stick
> the address of that object into the void*.  in the C code, you
> then cast it to whatever type you "know" the object is and twiddle
> the underlying memory directly.

I assume by this statement that the user puts everything in, or
otherwise you can keep some kind of table of names to types.

> the object can have any arbitrary C type, and the same function
> is used to lookup objects of many different C types.

Just how arbitrary do you mean?  The more important case is what type
restrictions *you* can guarantee, ignoring the C declaration.

> 
> so can anyone suggest a strategy for wrapping this thing? what
> might a nice scheme interface look like for this sort of api?

A procedure-with-setter, perhaps.  Since everything is SCMs, and an SCM
is guaranteed to fit in a void*, the user will slot those in.

If there are C objects put there by C, then those will need a table of
names to types.

If the user might put C objects in them and retrieve them with Guile,
and you don't want to force a table, you could write separate functions
for each type that may be retrieved.  This is inflexible and unsafe,
however.

-- 
Stephen Compall

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

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