lispgames / cl-sdl2

Common Lisp bindings for SDL2 using C2FFI.
MIT License
304 stars 82 forks source link

Remove conditionalizing on packages that are not required by dep: swank, etc #45

Closed vi1 closed 6 years ago

vi1 commented 9 years ago

Not really a bug, but can cause surprises as it did for me.

If you, say quickload sdl2 from emacs or vim in my case with swank loaded, then sdl2 will be compiled with #+swank code:

(defun sdl-main-thread () (let ((main-thread (bt:current-thread))

+swank (swank:sldb-quit-restart 'continue)

    etc

If you are later compile in sdl2 for use in standalone program it signals that no such symbol or something. It could be resolved by adding asdf dependence on swank, but it is obviously stupid. I guess such kind of conditionalizing should be done on user side somehow and not in the sdl2 itself.

vi1 commented 9 years ago

To clarify what I'm proposing. Have some hooks in sdl, like sdl2-whatever-hook and user can use it in his own config, like #+swank (setf sdl2-whatever-hook 'whatever).

rpav commented 9 years ago

I'm not sure this is possible for the restart code. Probably easier and arguably "desirable anyway" is just to signal in all cases, but use swank's stuff when available. I'll have to look into it.

vi1 commented 9 years ago

Oh yeah, dynamic bindings.

Some like this should work:

(defun dyn-bindings ()
  (let ((res nil)
        (swank (find-package :swank))
        (slynk (find-package :slynk)))
    (when swank
      (let ((sym (find-symbol "*SLDB-QUIT-RESTART*" swank)))
        (when sym
          (push sym res))))
    (when slynk
      (let ((sym (find-symbol "*SLY-DB-QUIT-RESTART*" slynk)))
        (when sym
          (push sym res))))
    res))

(defun sdl-main-thread ()
  (progv (dyn-bindings) '(continue continue)
    (let ((*main-thread* (bt:current-thread))
          ...

progv allows symbols and values lists to be of different sizes, so ex (progv () '(continue contrinue) ...) is fine

mfiano commented 6 years ago

No longer depends on swank or slynk.