Cocoa binding for CommonLisp on macOS.
It used CFFI.
- build C shared library.
$ cd /PATH/TO/cl-nextstep/ $ cd C $ cmake -B build $ make -C build
Cocoa binding for Common Lisp on macOS
Thank you for this excellent software and for all of your amazing work.
I wrote this macro which can make context.lisp
a bit less verbose. It's probably clearer not to use it!
(eval-when (:compile-toplevel :load-toplevel :execute)
(defun cgify-name (symbol)
"Convert 'lisp-name into \"CGContextLispName\"."
(let* ((segs (uiop:split-string (string symbol) :separator '(#\-)))
(title (loop for seg in segs
collect (cond ((string= seg "CTM") "CTM")
((string= seg "EO") "EO")
(t (string-capitalize seg))))))
(format nil "CGContext~{~a~}" title)))
(defun interpret-args (args)
"Convert list of args, with optional interleaved type keywords
(default :double), into defun-args (and cffi-args)."
(let ((next-type :double)
(defun-args (list))
(cffi-args (list)))
(dolist (arg args)
(if (keywordp arg)
(setf next-type arg)
(progn
(setf defun-args (nconc defun-args `(,arg)))
(setf cffi-args
(nconc cffi-args
(case next-type
(:double `(:double (cgfloat ,arg)))
(:rect `((:struct ns:rect) ,arg))
(otherwise `(,next-type ,arg)))))
(setf next-type :double))))
(values defun-args cffi-args))))
;; (cgify-name 'scale-ctm)
;; => "CGContextScaleCTM"
(defmacro defcall (symbol &optional args)
"Simplify cffi Core Graphics defuns."
(multiple-value-bind (defun-args cffi-args) (interpret-args args)
`(defun ,symbol (context ,@defun-args)
(cffi:foreign-funcall ,(cgify-name symbol)
:pointer context
,@cffi-args))))
;; (macroexpand-1 '(defcall stroke-rect-with-width (:rect rect width)))
;; => (DEFUN STROKE-RECT-WITH-WIDTH (CONTEXT RECT WIDTH)
;; (CFFI:FOREIGN-FUNCALL "CGContextStrokeRectWithWidth" :POINTER CONTEXT
;; (:STRUCT CL-NEXTSTEP:RECT) RECT :DOUBLE
;; (CGFLOAT WIDTH)))
;; T
First I ran these commands.
% cd ~/quicklisp/local-projects
% git clone https://github.com/byulparan/cl-nextstep
% cd cl-nextstep/C
% cmake -B build
% make -C build
Then I ran this in the REPL.
(ql:quickload "cl-nextstep")
But it failed to load with this error.
Subprocess #<UIOP/LAUNCH-PROGRAM::PROCESS-INFO {700D112903}>
with command ("clang" "-o"
"/Users/goldenphi/.cache/common-lisp/sbcl-2.2.9-macosx-arm64/Users/goldenphi/quicklisp/dists/quicklisp/software/cffi_0.24.1/libffi/libffi-types__grovel-tmpPB4O1YD8.o"
"-c" "-g" "-Wall" "-Wundef" "-Wsign-compare"
"-Wpointer-arith" "-O3" "-g" "-Wall"
"-fdollars-in-identifiers"
"-fno-omit-frame-pointer" "-I/opt/local/include/"
"-I/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk/usr/include/ffi"
"-fPIC"
"-I/Users/goldenphi/quicklisp/dists/quicklisp/software/cffi_0.24.1/"
"/Users/goldenphi/.cache/common-lisp/sbcl-2.2.9-macosx-arm64/Users/goldenphi/quicklisp/dists/quicklisp/software/cffi_0.24.1/libffi/libffi-types__grovel.c")
exited with error code 1
[Condition of type CFFI-GROVEL:GROVEL-ERROR]
^ ^ ^
/Users/goldenphi/.cache/common-lisp/sbcl-2.2.9-macosx-arm64/Users/goldenphi/quicklisp/dists/quicklisp/software/cffi_0.24.1/libffi/libffi-types__grovel.c:81:41: error: use of undeclared identifier 'FFI_UNIX64'
fprintf(output, "%"PRIiMAX, (intmax_t)FFI_UNIX64);
^
1 error generated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.