From: Sam Steingold <sds@gn...> - 2005-07-18 16:07:09
the way FFI users now handle
#define FOO 10
(defconstant FOO 10)
if FOO changes in the library, the FFI lisp file has to be changed.
how about creating a C var with the value FOO and then reading it with
(defmacro def-c-const (name c-type &optional (c-name (symbol-name name)))
(let ((low-name (intern (concatenate 'string "%" (symbol-name name))))
(c-var-name (concatenate 'string "clisp_var_" c-name)))
(c-lines "static ~A ~A = ~A~&" ,c-type ,c-var-name ,c-name)
(def-c-var ,low-name (:name ,c-var-name) (:type c-name) (:read-only t))
(defconstant ,name ,low-name))))
harder to make fully dynamic (c-lines !!)
waste of space for a variable used just once.
would you find this useful?
PS the same issues apply to def-c-enum and the same solution can be used.
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.memri.org/> <http://www.mideasttruth.com/>
Lisp is a way of life. C is a way of death.
Sam Steingold wrote:
>the way FFI users now handle
>#define FOO 10
>(defconstant FOO 10)
What you propose is loosing a property that people also make use of, which is the availability of the constant at compile-time, e.g. for sake of #.foo within (c-array x #.foo) or other such places.
I.e. you change the semantics and disable EVAL-WHEN (load COMPILE eval) around such constants.
Otherwise, do as you please. I for sure don't like C code to get compiled and modules machinery just to get some trivial constants.
There's indeed a problem with getting out of sync, e.g.
o cl-gd-0.2.2's xyz struct does not match what I found on my laptop in the .h file, befor it died (or was it cl-sdl)
o same for modules/postgres/notify-struct
But I don't see how trying to fix #define without handling struct and #ifdef is going to help people.
I'd leave stuff as is, and advocate people write functional interfaces between C and Lisp, instead of using #defines and slots. (Modules can be used to that effect). Such functional interfaces will also make interfacing from other languages easier.
Just my 0.00EUR,