Evaluating types in function definitions

John DeSoi <[email protected]> Mon, 1 Apr 2002 11:03:15 -0500
Newsgroups gmane.lisp.uffi.devel
Message-ID <p04330103b8ce32171857@[192.168.1.6]>
I would like to propose that parameter types and return values get 
evaluated when defining foreign functions.

Rationale: I'm working on an API that uses different parameters 
depending on the platform. For example, a function to open a database 
uses a cstring (path) on Windows and a file spec record pointer on 
the Mac. So I have my function:

(uffi:def-function ("DataBase_Create" ff-database-create)
   ((inFileSpec :fsspecptr)
    (inSizeOfCluster :long)
    (inMode :unsigned-short)
    (inNativeOS :unsigned-char))
   :module :vcsdk
   :returning :unsigned-long)


:fsspecptr is the built record type on the Mac. For Windows I have:

#-apple
(defconstant :fsspecptr :cstring)


With the added evaluation, I can define what I need in one place 
instead of adding conditional code to every function definition.


In the MCL version I added eval to the function below:

(defun process-one-function-arg (arg)
   (let ((name (car arg))
	(type (convert-from-uffi-type (eval (cadr arg)) :routine)))
     (if (and (listp type) (listp (car type)))
	(append (list name) type)
       (list name type))
     ))


And also used eval on the return value in def-function.


Any problem in doing this?

Thanks,

John DeSoi, Ph.D.