klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

ffi-gtk.k (664B)


      1 ;;
      2 ;; Dynamic FFI example.
      3 ;;
      4 ;; Inspired by example gtk.lua from Lua Alien FFI library
      5 ;; (the original is only 11 lines long, though...)
      6 ;;
      7 
      8 ($define! gtk (ffi-load-library "libgtk-x11-2.0.so.0"))
      9 ($define! i "sint")
     10 ($define! p "pointer")
     11 ($define! make
     12   ($lambda (rtype name . atypes)
     13     (ffi-make-applicative gtk name
     14       (ffi-make-call-interface "FFI_DEFAULT_ABI" rtype atypes))))
     15 
     16 ($define! gtk-init (make "void" "gtk_init" p p))
     17 ($define! gtk-message-dialog-new (make p "gtk_message_dialog_new" p i i i "string"))
     18 ($define! gtk-dialog-run (make i "gtk_dialog_run" p))
     19 
     20 (gtk-init () ())
     21 (gtk-dialog-run (gtk-message-dialog-new () 0 0 1 "Klisp Rocks!"))