-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathutils.lisp
36 lines (32 loc) · 934 Bytes
/
utils.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(in-package #:cv)
(defmacro define-cfun ((c-name name) return-type &body body)
`(progn
(defun ,name ,(loop for p in body
with optional = nil
with a = () with b = ()
do (if (= (length p) 2) (progn
(when optional (error "why not optional?"))
(push (car p) a))
(progn
(setf optional t)
(push (list (car p) (third p)) b)))
finally (return (append (reverse a) (cons '&optional (reverse b)))))
(cffi:foreign-funcall
,c-name
,@(mapcan
#'(lambda (p)
(destructuring-bind (var type &rest r)
p
(declare (ignore r))
(list type (case type
(:float `(coerce ,var 'single-float))
(:double `(coerce ,var 'double-float))
(:int `(floor ,var))
(otherwise var)))))
body)
,return-type))
(export ',name)))
(defmacro define-export-constant (name value)
`(progn
(defconstant ,name ,value)
(export ',name)))