Initial commit. Basic IL bindings and a couple of ILUT ones.
[cl-devil.git] / utilities.lisp
blobc89890e544bcc98e3c675d45e75ef8f59851082c
2 (in-package :cl-devil)
4 (defun w-i-args-helper (args)
5 (when args
6 `((bind-image it)
7 ,(cons
8 (cond ((= 1 (length args)) 'il:load-image)
9 ((= 3 (length args)) 'il:load-l)
10 ((stringp (second args)) 'il:load)
11 (t 'il:load-f))
12 args))))
14 (defmacro with-images ((&rest images) &body body)
15 "Generates an IL image for each of IMAGES, binding and loading if a parameter is supplied. BODY is executed, and the images are freed thereafter."
16 (let ((ids (gensym))
17 (count (length images)))
18 `(cffi:with-foreign-object (,ids :uint ,count)
19 (il:gen-images ,count ,ids)
20 (unwind-protect
21 (let (,@(loop for x in images
22 for (var . args) = (if (listp x) x (list x))
23 for i from 0
24 collect `(,var (anaphora:aprog1 (cffi:mem-ref ,ids :uint ,i)
25 ,@(w-i-args-helper args)))))
26 ,@body)
27 (il:delete-images ,count ,ids)))))
29 (il:with-images (urp arp (exit "/home/julian/exit.pcx")) (format t "~&~A ~A ~A" urp arp exit))