Skip to content

Instantly share code, notes, and snippets.

@cbaggers
Last active April 15, 2018 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbaggers/57b86555d35ef460dbcda254b1a37f8a to your computer and use it in GitHub Desktop.
Save cbaggers/57b86555d35ef460dbcda254b1a37f8a to your computer and use it in GitHub Desktop.
#+sbcl
(eval-when (:compile-toplevel :load-toplevel :execute)
(sb-int:set-floating-point-modes :traps nil))
(defpackage :moo (:use :cl))
(in-package :moo)
(cffi:define-foreign-library libsdl2
(:darwin (:or (:framework "SDL2") (:default "libSDL2")))
(:unix (:or "libSDL2-2.0.so.0" "libSDL2.so.0.2" "libSDL2"))
(:windows "SDL2.dll")
(t (:default "libSDL2")))
(cffi:use-foreign-library libsdl2)
(defun print! (x &rest args)
(format t "~%~a~{ ~s~}" x args)
(finish-output)
x)
(defconstant +everything+
#.(logior #x00000001
#x00000010
#x00000020
#x00000200
#x00001000
#x00002000
#x00004000))
;; int SDL_Init(Uint32 flags)
(cffi:defcfun ("SDL_Init" sdl_init) :int
(flags :uint32))
;; Uint32 SDL_WasInit(Uint32 flags)
(cffi:defcfun ("SDL_WasInit" sdl_was_init) :uint32
(flags :uint32))
;; void SDL_Quit(void)
(cffi:defcfun ("SDL_Quit" sdl_quit) :void)
;;void SDL_PumpEvents(void)
(cffi:defcfun ("SDL_PumpEvents" sdl_pump_events) :void)
(defun my-init ()
(sdl_init +everything+))
(defun my-was-init ()
(sdl_was_init +everything+))
(defun my-quit ()
(sdl_quit))
(defun my-pump ()
(sdl_pump_events))
(defun death ()
(print! "hi")
(print! "about to init")
(assert (>= (my-init) 0))
;;(sdl2:create-window)
(print! "was init" (my-was-init))
(unwind-protect
(progn
(print! "next will poll a single event a bunch of times")
(loop :for i :below 300 :do (my-pump))
(print! "event poll'd"))
(print! "about to quit")
(print "quit:" (my-quit))
(print! "successfully quit")))
;; - `(ql:quickload :cffi)`
;; - compile this file
;; - `(moo::death)`
;; - dies with 'Process inferior-lisp segmentation fault: 11'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment