(in-package :common-lisp-user) (defpackage :HEADER (:use :common-lisp) (:export :A_CONSTANT :struct_t :make-struct_t :struct_t-x :struct_t-y :struct_t-x :struct_t-y :enum_t :SDL_AUDIO_STOPPED :SDL_AUDIO_PLAYING :SDL_AUDIO_PAUSED :SDL_AUDIO_STOPPED :SDL_AUDIO_PLAYING :SDL_AUDIO_PAUSED :union_t :my_type :enum_G5160_t :SDL_NOEVENT :SDL_ACTIVEEVENT :SDL_USEREVENT :SDL_NUMEVENTS :SDL_NOEVENT :SDL_ACTIVEEVENT :SDL_USEREVENT :SDL_NUMEVENTS :my_var :my_var_enum :my_func :my_func_string :my_div :my_func_enum :my_func_with_func)) (in-package :HEADER) #-CLISP (uffi:load-foreign-library "test.so" :module "test.so" :supporting-libraries '("c")) ;;; COMMENT: /* This is a comment { boo } ; foo comment */ ;; /* This is a comment { boo } ; foo comment */ ;;; COMMENT: /* This is a comment BoooO // foooo on several * lines foo */ ;; /* This is a comment BoooO // foooo on several * lines foo */ ;;; DEFINE: #ifdef _cpp ;; **IGNORED**: #ifdef _cpp ;;; CODE: toto { } ;; **IGNORED**: toto { } ;;; DEFINE: #endif ;; **IGNORED**: #endif ;;; DEFINE: #include ;; **IGNORED**: #include ;;; DEFINE: #define A_CONSTANT 10 (defconstant A_CONSTANT 10) ;;; DEFINE: #define inflateBackInit(strm, windowBits, window) inflateBackInit_((strm), (windowBits), (window), ZLIB_VERSION, sizeof(z_stream)) ;; **IGNORED**: #define inflateBackInit(strm, windowBits, window) inflateBackInit_((strm), (windowBits), (window), ZLIB_VERSION, sizeof(z_stream)) ;;; COMMENT: /* x param */ ;; /* x param */ ;;; COMMENT: /* y param */ ;; /* y param */ ;;; CODE: typedef struct { int x; int y; } struct_t; #+CLISP (ffi:def-c-struct (struct_t :typedef) (x ffi:int) (y ffi:int)) #-CLISP (progn (uffi:def-struct struct_t (x :int) (y :int)) (defmacro struct_t-x (s) `(uffi:get-slot-value ,s 'struct_t 'x)) (defmacro struct_t-y (s) `(uffi:get-slot-value ,s 'struct_t 'y)) (defun make-struct_t (&key x y) (let ((s (uffi:allocate-foreign-object 'struct_t))) (setf (struct_t-x s) x) (setf (struct_t-y s) y) s))) ;;; CODE: typedef enum { SDL_AUDIO_STOPPED = 0, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED } enum_t; #+CLISP (ffi:def-c-enum enum_t (SDL_AUDIO_STOPPED 0) SDL_AUDIO_PLAYING SDL_AUDIO_PAUSED) #-CLISP (progn (uffi:def-enum enum_t ((:SDL_AUDIO_STOPPED 0) :SDL_AUDIO_PLAYING :SDL_AUDIO_PAUSED )) (defconstant SDL_AUDIO_STOPPED enum_t#SDL_AUDIO_STOPPED) (defconstant SDL_AUDIO_PLAYING enum_t#SDL_AUDIO_PLAYING) (defconstant SDL_AUDIO_PAUSED enum_t#SDL_AUDIO_PAUSED)) ;;; CODE: typedef union { int a; float b; struct_t c; } union_t; #+CLISP (ffi:def-c-type union_t (ffi:c-union (a ffi:int) (b ffi:single-float) (c struct_t))) #-CLISP (uffi:def-union union_t (a :int) (b :float) (c struct_t)) ;;; CODE: typedef unsigned long my_type; #+CLISP (ffi:def-c-type my_type ffi:ulong) #-CLISP (uffi:def-foreign-type my_type :unsigned-long) ;;; COMMENT: /* Unused (do not remove) */ ;; /* Unused (do not remove) */ ;;; COMMENT: /* Application loses/gains visibility */ ;; /* Application loses/gains visibility */ ;;; COMMENT: /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */ ;; /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */ ;;; COMMENT: /* This last event is only for bounding internal arrays It is the number of bits in the event mask datatype -- Uint32 */ ;; /* This last event is only for bounding internal arrays It is the number of bits in the event mask datatype -- Uint32 */ ;;; CODE: enum { SDL_NOEVENT = 0, SDL_ACTIVEEVENT, SDL_USEREVENT = 24, SDL_NUMEVENTS = 32 }; #+CLISP (ffi:def-c-enum enum_G5164_t (SDL_NOEVENT 0) SDL_ACTIVEEVENT (SDL_USEREVENT 24) (SDL_NUMEVENTS 32)) #-CLISP (progn (uffi:def-enum enum_G5164_t ((:SDL_NOEVENT 0) :SDL_ACTIVEEVENT (:SDL_USEREVENT 24) (:SDL_NUMEVENTS 32) )) (defconstant SDL_NOEVENT enum_G5164_t#SDL_NOEVENT) (defconstant SDL_ACTIVEEVENT enum_G5164_t#SDL_ACTIVEEVENT) (defconstant SDL_USEREVENT enum_G5164_t#SDL_USEREVENT) (defconstant SDL_NUMEVENTS enum_G5164_t#SDL_NUMEVENTS)) ;;; CODE: int my_var; #+CLISP (ffi:def-c-var my_var (:name "my_var") (:type ffi:int) (:library "test.so")) #-CLISP (uffi:def-foreign-var ("my_var" my_var) :int "test.so") ;;; CODE: enum_t my_var_enum ; #+CLISP (ffi:def-c-var my_var_enum (:name "my_var_enum") (:type enum_t) (:library "test.so")) #-CLISP (uffi:def-foreign-var ("my_var_enum" my_var_enum) enum_t "test.so") ;;; CODE: int my_func (void); #+CLISP (ffi:def-call-out my_func (:name "my_func") (:return-type ffi:int) (:arguments) (:language :STDC) (:library "test.so")) #-CLISP (uffi:def-function ("my_func" my_func) () :returning :int :module "test.so") ;;; CODE: char * my_func_string (char * str); #+CLISP (ffi:def-call-out my_func_string (:name "my_func_string") (:return-type ffi:c-string) (:arguments (str ffi:c-string)) (:language :STDC) (:library "test.so")) #-CLISP (uffi:def-function ("my_func_string" my_func_string) ( (str :cstring)) :returning :cstring :module "test.so") ;;; COMMENT: /* an other comment */ ;; /* an other comment */ ;;; CODE: struct_t * my_div (int px, int py); #+CLISP (ffi:def-call-out my_div (:name "my_div") (:return-type (ffi:c-ptr struct_t)) (:arguments (px ffi:int) (py ffi:int)) (:language :STDC) (:library "test.so")) #-CLISP (uffi:def-function ("my_div" my_div) ( (px :int) (py :int)) :returning (* struct_t) :module "test.so") ;;; CODE: enum_t my_func_enum (float f); #+CLISP (ffi:def-call-out my_func_enum (:name "my_func_enum") (:return-type enum_t) (:arguments (f ffi:single-float)) (:language :STDC) (:library "test.so")) #-CLISP (uffi:def-function ("my_func_enum" my_func_enum) ( (f :float)) :returning enum_t :module "test.so") ;;; CODE: void my_func_with_func (int (* callback) (int x, char * str)); #+CLISP (ffi:def-call-out my_func_with_func (:name "my_func_with_func") (:return-type NIL) (:arguments (callback (ffi:c-function (:return-type ffi:int) (:arguments (x ffi:int) (str ffi:c-string)) (:language :STDC)))) (:language :STDC) (:library "test.so")) #-CLISP (uffi:def-function ("my_func_with_func" my_func_with_func) ( (callback (* (function :int :int :cstring)))) :returning :void :module "test.so")