Re: UFFI-izing varargs
- From: Kenny Tilton <ktilton@xxxxxxxxxx>
- Date: Tue, 31 May 2005 02:34:20 GMT
Frank Goenninger DG1SBG wrote:
While trying to write a (working) interface to the syslog family of C functions I came across the varargs problem:
The C function is defined as:
void syslog( int priority, const char *messae, ...)
Hm - how to transform this into a suitable UFFI definition and how to call it then ?
I have so far:
###
;; FUNCTION DEFINITION
(uffi:def-function ("syslog" _syslog) ((priority :int) (message :cstring)) :returning :void)
;; SYSLOG: CALLING THE C FUNCTION
(defun syslog (priority message &rest args)
(declare (ignorable args))
;; write message to syslog
(with-cstring (c-message message) (_syslog priority c-message)) )
###
That's obviously only half of the thing I want. So,
my questions are:
1. How to deal with the &rest args ?
Don't you want an array of pointers where you have (message :cstring) in the UFFI definition? Then you just populate the Lisp array (suitably defined using UFFI) and pass that.
Is this the right approach ?
2. How to call `format' to transform the args into one string which can then be passed to syslog ?
I see that using approach 2) properly there's no need for a varargs definition any more. So, 2) means how to loop ober the args ... Oh, wait, that should be easy ;-) It once again shows that I am still a newbie.
For fun you can look at format args ~{/~} to explore handily formatting a list.
kenzo
-- Cells? : http://www.common-lisp.net/project/cells/ Cello? : http://www.common-lisp.net/project/cello/ Cells-Gtk? : http://www.common-lisp.net/project/cells-gtk/ Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film
"Doctor, I wrestled with reality for forty years, and I am happy to state that I finally won out over it." -- Elwood P. Dowd
.
- References:
- UFFI-izing varargs
- From: Frank Goenninger DG1SBG
- UFFI-izing varargs
- Prev by Date: win32 Lisp cannot load Gtk DLLs when C can?
- Next by Date: Re: Lisp geographic software
- Previous by thread: UFFI-izing varargs
- Next by thread: Lisp geographic software
- Index(es):