5

I'm trying to manage some events in lisp with lispbuilder-sdl.

Thus far I got this.

;; Load package :
(ql:quickload "lispbuilder-sdl")

;; main definition:
(defun main (argv)
  (defparameter *ticks* 0)
  (sdl:with-init ()
    (sdl:window 100 100 :title-caption "test")
    (sdl:with-events ()
      (setf (sdl:frame-rate) 60)
      (:quit-event () (progn (sdl:quit-image) (exit) t))
      (:mouse-button-down-event 
       (:button button :x x :y y)
       (format t "~&LSHIFT: ~a RSHIFT: ~a BUTTON: ~a X: ~d Y: ~d" 
               (sdl:get-key-state :sdl-key-lshift) 
               (sdl:get-key-state :sdl-key-rshift) 
               button x y))
      (:key-down-event 
       (:key key)
       (format t "~& KEY: ~a" key))
      (:idle ()))))



;; Entrypoint :
(sb-int:with-float-traps-masked (:invalid :inexact :overflow) (main *posix-argv*))

If I launch this, a window appear, I can click and roll, I got an output to describe the state of the keys and buttons pressed. Same if I press a key down. Fine.

But something weird occurs when I keep a shift key down.

If I do so, I still have the output when clicking. But not when rolling (mouse wheel events).

So I guess mouse-wheel events simply arent triggered when a shift (right or left) is down. But only shift keys, and I don't even know why.

So I can't for instance handle shift+mouse-wheel events.

Any idea?

NB : The version of SBCL I use on OSX is 1.2.11 but it works with both 1.3.2 and 1.2.11 on Ubuntu.

Gustav Bertram
  • 14,591
  • 3
  • 40
  • 65
vmonteco
  • 14,136
  • 15
  • 55
  • 86
  • 1
    I can't reproduce the problem on linux+sbcl, but you should clean that indentation a bit. I suppose emacs doesn't know how to indent the events properly, so you should just manually indent their body 2 spaces (or use something like (emacs lisp) `(put 'sdl:with-events 'common-lisp-indent-function '(4 &rest (&whole 2 4 &rest 2)))` to tell Emacs how to do it). All those `progn`s seem to be unnecessary as well, and you probably should just use `format` instead of multiple `print`s. – jkiiski Feb 23 '16 at 14:06
  • You're right, I'll try to install SLIME to do this then. Perhaps it has something to do with the OS? my project seemed able to handle this on a linux, but right now I'm working on OSX. I'll retry at home after work. – vmonteco Feb 23 '16 at 14:17
  • @jkiiski I made a VM to test and compare, and I wasn't able to reproduce it either on ubuntu. I tried both sbcl 1.3.2 and 1.2.11 (I'm using the 1.2.11 on OSX) but it wasn't a version problem either. – vmonteco Feb 23 '16 at 17:54
  • Can you try if it works on some other implementation on OSX to see if the problem is with sbcl or lispbuilder-sdl? I don't have other OSes available to test on myself. – jkiiski Feb 23 '16 at 17:59
  • @jkiiski I'm not sure about what you suggested. Did you suggest to me to try with an over sbcl version on OSX? – vmonteco Feb 23 '16 at 22:29
  • @jkiiski Though... http://lispbuilder.sourceforge.net/lispbuilder-sdl.html#compatibility – vmonteco Feb 23 '16 at 22:35
  • I meant try with some other Common Lisp implementation besides SBCL. That table seems to say that CLISP should work. In case you're not aware, both SBCL and CLISP are implementations of the same Common Lisp standard (as are the others mentioned on that table), so you can switch to another one without any major changes to your code (unless you're using lots of SBCL's non-standard extensions like that `sb-int:with-float-traps-masked`) – jkiiski Feb 24 '16 at 05:41
  • @jkiiski I tried to **ql:quickload** "lispbuilder-sdl" but I get "**- CFFI requires CLISP compiled with dynamic FFI support.** with CLISP, I'm trying to find a solution that doesn't require root access. – vmonteco Feb 25 '16 at 11:20
  • 1
    Try the answer from [this older question](http://stackoverflow.com/questions/3901698/is-there-a-way-to-get-the-clisp-compiled-with-dynamic-ffi-support-on-mac-os). If it doesn't work, I think you need to compile it from source using `--with-dynamic-ffi` as an argument to configure. – jkiiski Feb 25 '16 at 11:42
  • @jkiiski I already tried but I have no root access (hence the need for an answer without a sudo call), I'll try the compilation then. – vmonteco Feb 25 '16 at 11:55
  • @jkiiski Hello again! I've finally found the time to try the compilation, but I have the same problem that the post you linked. And the validated solution doesn't work because I have no root access. I've installed libsigsegv and libffi with brew but even with `--with-segv-prefix` it doesn't work. I've also tried to install it like the error message suggests. If I try to skip and to run make, I got a C compilation error : `avcall.h : file not found` – vmonteco Apr 25 '16 at 18:31
  • @jkiiski I've made a new post about this compilation problem if it interests you :) : http://stackoverflow.com/questions/36849567/compiling-clisp-2-49-on-osx-libffi-not-found – vmonteco Apr 25 '16 at 19:50
  • Have you tested SDL directly with other languages on Mac OS X? – Gustav Bertram Apr 10 '17 at 14:29

0 Answers0