guile-user
[Top][All Lists]
Advanced

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

RE: Using a C pointer in Guile


From: Brian McAndrews
Subject: RE: Using a C pointer in Guile
Date: Wed, 24 Oct 2001 11:21:40 -0500

Thanks,

How about a mapping between C structs and Scheme that can be defined a
runtime?

ie:)
struct Date {
int y;
int m;
int d;
};

Just a scheme newbie, so I'm not sure how this would happen in scheme:
(define-c-struct Date (
                 c_int y
                 c_int m
                 c_int d))
(assign-ref my_scheme_ref my_c_pointer Date)
(my_scheme_ref d  12)  now what the C side sees is its d changed to 12.

I know I've badly messed up the scheme stuff, but I hope what I'm trying to
gets across.

The idea is to map the C data layout to the scheme data layout and then
assign a pointer to it.  Thus, when a new data type is added to the C world,
you can describe it's layout on the scheme side without having to generate
more C binding code?  Also, the memory for the C data structures that I want
to define (Date) needs only to be managed on the C side (I don't need to
create a new Date in guile, I just want to use a date and modify it).


Is this pratical?  Or am I completely messed up?

Thanks,
Brian


-----Original Message-----
From: Robert A. Uhl [mailto:address@hidden
Sent: Tuesday, October 23, 2001 5:37 PM
To: Brian McAndrews
Subject: Re: Using a C pointer in Guile


On Tue, Oct 23, 2001 at 04:41:14PM -0500, Brian McAndrews wrote:
> I want to have the ability to pass a C pointer to guile.  I then want to
> modify the data structure pointed to by the pointer such that those
changes
> are reflected back on the C side of things.  For example, if I had a data
> structure that contained information about an automobile (ie,
> number_of_doors, gas_mileage, weight...), but I wanted to review that data
> structure in guile, and change one of the parameters.  How would I do
that?
> Is that what smobs are for?

Yup.  Write a function to return a new smob, then write various
functions to manipulate its data.  So your guile code might look like:

(define auto (new-auto))
(set-auto-gas-mileage auto (* 2 (get-auto-gas-mileage auto)))

--
Robert Uhl <address@hidden>

Interestingly, most Unix utilities have a command line option which will
cause the system to rip the user's legs off and beat them to death with
the soggy ends.  This is often the default behaviour.    --Bruce Murphy






reply via email to

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