Hello,
I'm having some difficulty passing arguments to defcfun. This is likely due to my incomplete knowledge of lisp, so hopefully someone can point me in the right direction. Given the following code:
defpackage :cffi-test (:use :common-lisp :cffi))
(in-package :cffi-test)
(defun strip-args (args) (let ((new-args nil)) (dolist (elm (car args)) (setf new-args (append new-args (list (subseq elm 0 2))))) new-args))
(defun make-defcfun-call (c-name lisp-name returns &rest args) `(defcfun (,c-name ,lisp-name) ,returns ,@(strip-args args)))
(defmacro pl-defcfun (name returns &rest args) (make-defcfun-call (elt name 0) (elt name 1) returns args))
(defmacro pl-defcfun-2 (name returns &rest args) (make-defcfun-call (elt name 0) (make-symbol (format nil "bar- ~A" (elt name 1))) returns args))
This creates a function called l-foo:
(pl-defcfun ("c-foo" l-foo) :void (x :char) (y :char))
This should create a function call bar-l-foo (or maybe #|bar-l- foo|?), but doesn't appear to (as judged by my not getting a function prototype at the slime REPL).
(pl-defcfun-2 ("c-foo" l-foo) :void (x :char) (y :char))
Maybe defcfun is not getting the right kind of symbol? I am running SBCL 0.9.9 with a few week old version of slime from cvs on OS-X 10.4.
Thanks for your help, -Hazen
On Wed, 2006-03-01 at 00:21 -0500, Hazen Babcock wrote:
This should create a function call bar-l-foo (or maybe #|bar-l- foo|?), but doesn't appear to (as judged by my not getting a function prototype at the slime REPL).
The easiest way to debug macros is to expand them by putting point at the opening paren in a Lisp mode buffer and doing C-c RET (or C-c C-m). You can do this recursively in the resultant Macroexpansion buffer, and (soon?) will be able to expand forms in place.
Maybe defcfun is not getting the right kind of symbol?
You got it, the symbol you are generating is #:|bar-L-FOO| as make-symbol doesn't intern its result, and you didn't normalize the case of the string you gave to it anyway. Some people like to READ-FROM-STRING to get a reasonable symbol from a string; there are other ways to get a reasonable symbol.