Hi there.
Your current implementation of "parse-args-and-types" in src/function.lisp
use destructuring clause in "loop" and tests the end(as i understood) of the
arguments list by comparing second value with nil
(defun parse-args-and-types (args)
"Returns 4 values. Types, canonicalized types, args and return type."
(let ((return-type :void))
(loop for (type arg) on args by #'cddr
if arg collect type into types
and collect (canonicalize-foreign-type type) into ctypes
and collect arg into fargs
else do (setf return-type type)
finally (return (values types ctypes fargs return-type)))))
but it also causes foreign-funcall to skip argument if it's value is NIL:
(define-foreign-type ptr-type () ()
(:actual-type :pointer)
(:simple-parser some-type))
(defmethod translate-to-foreign (val (type ptr-type))
(if (null val) (null-pointer) val))
(foreign-funcall "f" :uint x some-type nil :uint y :void)
==>
(LET ((#:G13879 X))
(LET ((#:G13880 Y))
(CFFI-SYS:%FOREIGN-FUNCALL "f"
(:UNSIGNED-INT #:G13879 :UNSIGNED-INT #:G13880 :VOID)
:CALLING-CONVENTION
:CDECL :LIBRARY :DEFAULT)))
Shouldn't that function be written like this(for example)?
(defun parse-args-and-types (args)
"Returns 4 values. Types, canonicalized types, args and return type."
(let* ((len (length args))
(return-type (if (oddp len) (car (last args)) :void)))
(loop repeat (floor len 2)
for (type arg) on args by #'cddr
collect type into types
collect (canonicalize-foreign-type type) into ctypes
collect arg into fargs
finally (return (values types ctypes fargs return-type)))))
p.s. sorry for my bad english :)