guile-user
[Top][All Lists]
Advanced

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

Using Guile in C for program startup config


From: Luke Hammer
Subject: Using Guile in C for program startup config
Date: Wed, 29 Aug 2001 00:39:32 +1000

Hello,

Loving Emacs as I do, I jumped at the opportunity to use a LISPish
interface in a program of my own, and so I have recently been tinkering
with embedding Guile (using a precompiled version of 1.4 for Win32) in
an OpenGL particle system program I've been playing with, in order to
have it load a Scheme config file and initialise some data structures
when the program loads. Currently, I use only one SCM function to do
this, namely load-gravdata, so the config file looks something like
this:

(load-gravdata 0 0 0 "save1")

(load-gravdata 0 0 1 12.0)
(load-gravdata 0 0 2 13.0)
(load-gravdata 0 0 3 14.0)
(load-gravdata 0 0 4 0.01)
(load-gravdata 0 0 5 1)

(load-gravdata 0 1 1 15.0)
(load-gravdata 0 1 2 16.0)
(load-gravdata 0 1 3 17.0)
(load-gravdata 0 1 4 0.011)
(load-gravdata 0 1 5 1)

....where the first argument indicates which of 30 possible
configuration sets is being loaded, the second arg which of the 10
gravitation points in the set is being dealt with, third arg states
which field (xpos, ypos, zpos, mass etc) is being set, and fourth arg
gives the actual value to use for the field. The SCM load_gravdata
function in the C code then performs the appropriate assigment inside a
switch. This works, but seems somewhat inelegant. Someone suggested that
I do something more like this:

(grav-config "save1"
      (point 1 '(12 13 14 0.01 1))
      (point 2 '(15 16 17 0.011 0))
      [point 3 etc ...] )

This makes more sense, because it groups the point data within a single
config set. I'm just not sure how to deal with such a structure in the C
code....what would the point function, as it appears in the C code,
actually do? Presumably it would return something that grav-config could
use to initialise a point with? perhaps I would be better ommitting
point and just passing grav-config a list of lists? I'm not really sure
where to go next, or how to implement the interface to it in C....

I would welcome anyone's comments/suggestions on this, and I would also
welcome any tips regarding how to go the other way: how to write the
information in a C data structure back to scheme code like the above, to
be saved to a config file....

Thanks in advance,
Luke






reply via email to

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