Ramarren / cffi-stfl

Common Lisp bindings for STFL terminal widget library

This URL has Read+Write access

cffi-stfl / bindings.lisp
100644 49 lines (37 sloc) 2.042 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(in-package :cffi-stfl)
 
(define-foreign-library stfl (:unix "./libstfl.so"))
 
(use-foreign-library stfl)
 
(defparameter *ipool* nil)
 
(defctype stfl-form :pointer "STFL form handler")
(defctype stfl-string :pointer)
 
(defcfun (%create "stfl_create") stfl-form (text stfl-string))
(defcfun (%free "stfl_free") :void (form stfl-form))
(defcfun (%run "stfl_run") stfl-string (form stfl-form) (timeout :int))
(defcfun (reset "stfl_reset") :void)
(defcfun (%get "stfl_get") stfl-string (form stfl-form) (name stfl-string))
(defcfun (%set "stfl_set") :void (form stfl-form) (name stfl-string) (value stfl-string))
(defcfun (%get-focus "stfl_get_focus") stfl-string (form stfl-form))
(defcfun (%set-focus "stfl_set_focus") :void (form stfl-form) (name stfl-string))
(defcfun (%stfl-quote "stfl_quote") :void (text stfl-string))
(defcfun (%dump "stfl_dump") stfl-string (form stfl-form) (name stfl-string) (prefix stfl-string) (focus :int))
(defcfun (%modify "stfl_modify") :void (form stfl-form) (name stfl-string) (mode stfl-string) (text stfl-string))
(defcfun (%lookup "stfl_lookup") stfl-string (form stfl-form) (path stfl-string) (newname stfl-string))
(defcfun (%get-error "stfl_error") stfl-string)
(defcfun (%error-action "stfl_error_action") :void (mode stfl-string))
 
;;; ipool
 
(defctype stfl-ipool :pointer)
 
(defcfun (ipool-create "stfl_ipool_create") stfl-ipool (code :string))
(defcfun (ipool-add "stfl_ipool_add") :void (pool stfl-ipool) (data :pointer))
(defcfun (ipool-towc "stfl_ipool_towc") stfl-string (pool stfl-ipool) (buf :string))
(defcfun (ipool-fromwc "stfl_ipool_fromwc") :string (pool stfl-ipool) (buf stfl-string))
(defcfun (ipool-flush "stfl_ipool_flush") :void (pool stfl-ipool))
(defcfun (ipool-destroy "stfl_ipool_destroy") :void (pool stfl-ipool))
 
(defun ipool-reset ()
  (if *ipool*
      (ipool-flush *ipool*)
      (setf *ipool* (ipool-create "UTF8"))))
 
(defun towc (text)
  (ipool-towc *ipool* text))
 
(defun fromwc (stfl-text)
  (ipool-fromwc *ipool* stfl-text))
 
(declaim (inline ipool-reset towc fromwc))