I'm wondering if anyone has any suggestions as to how and go about
making the following macro act more like a DEFPACKAGE-style macro:
(defmacro with-allegro ((&key (width 640)
(height 480)
(depth 32)
(fullscreen)
(keyboard t)
(mouse t)
(title))
&body body)
(let ((install-progn (append (when title `((set-window-title ,title)))
(when keyboard '((install-keyboard)))
(when mouse '((install-mouse))))))
`(when (allegro-init) ,@install-progn
(set-color-depth ,depth)
(when (zerop (set-gfx-mode (if ,fullscreen 1 2)
,width
,height
0
0))
,@body)
(allegro-exit))))
Right now, to use this function, I do something like this:
(with-allegro (:keyboard nil
:width 800
:height 600
:fullscreen t
:title "My simple app")
(do-stuff-here))
This just feels unwieldy, and I was wondering how I could go about
doing two things:
1. Make it more DEFPACKAGE-like:
(with-allegro (:width 800)
(:height 600)
(do-stuff-here))
2. Fix up INSTALL-PROGN to be a lot more elegant. Right now it feels
very much like a hack. The basic premise is that if TITLE is NIL, then
don't call SET-WINDOW-TITLE, etc.
Jeff M.
--
(surf-to "http://www.retrobyte.org/")
"Jeff" <·······@gmail.com> writes:
> I'm wondering if anyone has any suggestions as to how and go about
> making the following macro act more like a DEFPACKAGE-style macro:
>
> (defmacro with-allegro ((&key (width 640)
> (height 480)
> (depth 32)
> (fullscreen)
> (keyboard t)
> (mouse t)
> (title))
> &body body)
> (let ((install-progn (append (when title `((set-window-title ,title)))
> (when keyboard '((install-keyboard)))
> (when mouse '((install-mouse))))))
> `(when (allegro-init) ,@install-progn
> (set-color-depth ,depth)
> (when (zerop (set-gfx-mode (if ,fullscreen 1 2)
> ,width
> ,height
> 0
> 0))
> ,@body)
> (allegro-exit))))
>
> Right now, to use this function, I do something like this:
>
> (with-allegro (:keyboard nil
> :width 800
> :height 600
> :fullscreen t
> :title "My simple app")
> (do-stuff-here))
>
> This just feels unwieldy, and I was wondering how I could go about
> doing two things:
>
> 1. Make it more DEFPACKAGE-like:
>
> (with-allegro (:width 800)
> (:height 600)
> (do-stuff-here))
(defmacro with-allegro-like-defpackage ((&rest options) &body body) ...)
(defmacro with-allegro-like-defpackage (&rest options-and-body) ...)
You'll have to parse the options and body yourself...
Add more default options: (fullscreen t) (title "Untitled").
Your macro is like WITH-OPEN-FILE, which is nice.
> 2. Fix up INSTALL-PROGN to be a lot more elegant. Right now it feels
> very much like a hack. The basic premise is that if TITLE is NIL, then
> don't call SET-WINDOW-TITLE, etc.
You can write it like that:
`(when (allegro-init)
,@(when title `((set-window-title ,title)))
,@(when keyboard '((install-keyboard)))
,@(when mouse '((install-mouse))))
(set-color-depth ,depth)
...)
--
__Pascal Bourguignon__ http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.
Jeff wrote:
> I'm wondering if anyone has any suggestions as to how and go about
> making the following macro act more like a DEFPACKAGE-style macro:
>
Not so much like defpackage, but as more functional style. defpackage
does not have a body so it can get away with that style. You are
better off grouping your args in a list.
(defun set-allegro-interface (&key (width 640) (height 480) (depth 32)
fullscreen (keyboard t) (mouse t) title)
(when title (set-window-title title))
(when keyboard (install-keyboard))
(when mouse (install-mouse))
(set-color-depth depth)
(set-gfx-mode (if fullscreen 1 2) width height 0 0))
(defmacro with-allegro (interface-args &body body)
`(when (allegro-init)
(when (zerop (set-allegro-interface ,@interface-args))
,@body)
(allegro-exit)))
Wade