Something went wrong. Try again.
Common Lisp bindings for egui
Something went wrong. Try again.
12345678910111213141516171819202122232425262728(in-package #:egui)
(defmacro with-utf8 (((pointer length) string) &body body) "Bind POINTER and LENGTH to a UTF-8 copy of STRING. A NIL STRING binds a nullpointer, which the shim reads as an absent optional argument; any string,including an empty one, binds a non-null pointer." (let ((value (gensym "STRING")) (size (gensym "SIZE"))) `(let ((,value ,string)) (if (null ,value) (let ((,pointer (cffi:null-pointer)) (,length 0)) (declare (ignorable ,pointer ,length)) ,@body) (cffi:with-foreign-string ((,pointer ,size) ,value :encoding :utf-8) (let ((,length (1- ,size))) ,@body))))))
(defun foreign-utf8 (pointer length) (if (zerop length) "" (cffi:foreign-string-to-lisp pointer :count length :encoding :utf-8)))
(defmacro with-returned-utf8 ((pointer-var length-var) &body body) "Run BODY with out-pointers for a string the shim returns, then convert it." `(cffi:with-foreign-objects ((,pointer-var :pointer) (,length-var :size)) ,@body (foreign-utf8 (cffi:mem-ref ,pointer-var :pointer) (cffi:mem-ref ,length-var :size))))