/ src /
/src/qstring.lisp
1 (in-package :cl-smoke.qt.core)
2
3 (defcfun cl-smoke-string-to-qstring :pointer
4 (data :string)
5 (length :int))
6
7 (defcfun cl-smoke-free-qstring :void
8 (string :pointer))
9
10 (defcfun cl-smoke-qstring-to-byte-array :pointer
11 (qstring :pointer))
12
13 ;;; make sure, that you have configured slime correctly.
14 ;;; e.g.:
15 ;;; (string #\U9999) crashed slime for me. Adding
16 ;;; (set-language-environment "UTF-8")
17 ;;; (setq slime-net-coding-system 'utf-8-unix)
18 ;;; to .emacs helps.
19 ;;; Use emacs 23 for better unicode support.
20 (smoke:eval-startup (:compile-toplevel :execute)
21 (qt:text-codec.set-codec-for-cstrings
22 (qt:text-codec.codec-for-name (string *default-foreign-encoding*)))
23 (qt:text-codec.set-codec-for-locale
24 (qt:text-codec.codec-for-name (string *default-foreign-encoding*))))
25
26 (smoke:eval-startup (:compile-toplevel :execute)
27 (let ((method (smoke::make-smoke-method-from-name (find-class 'qt:byte-array)
28 "constData")))
29 (defmethod cxx:const-data ((array qt:byte-array))
30 (values ;; Discharge second return value (length of string)
31 (foreign-string-to-lisp (smoke::pointer-call method
32 (smoke::pointer array))
33 :count (cxx:size array))))))
34
35 (defun from-qstring (qstring)
36 (cxx:const-data (make-instance 'qt:byte-array
37 :pointer (cl-smoke-qstring-to-byte-array qstring))))
38
39 (define-to-lisp-translation ("QString" "const QString&")
40 from-qstring cl-smoke-free-qstring)
41
42 (defun coerce-qstring (string)
43 (make-cleanup-pointer
44 (with-foreign-string ((data length) string :null-terminated-p nil)
45 (cl-smoke-string-to-qstring data length))
46 #'cl-smoke-free-qstring))
47
48 (define-from-lisp-translation ("const QString&" "QString") string
49 coerce-qstring)
50
51 (defmethod print-object ((object qt:byte-array) stream)
52 (if (null-pointer-p (pointer object))
53 (call-next-method)
54 (print-unreadable-object (object stream :type t :identity t)
55 (when (smoke::const-p object)
56 (princ "CONST " stream))
57 (prin1 (cxx:const-data object) stream))))