Code Monkey home page Code Monkey logo

cl-nextstep's Introduction

CL-NEXTSTEP

Cocoa binding for CommonLisp on macOS.
It used CFFI.

USAGE

  1. build C shared library.
    $ cd /PATH/TO/cl-nextstep/
    $ cd C
    $ cmake -B build
    $ make -C build
    

cl-nextstep's People

Contributors

byulparan avatar

Stargazers

Jeffrey Palmer avatar Jacob Vallejo avatar  avatar Yukihito avatar Maris Orbidans avatar Lord Horacio avatar Danny O'Brien avatar Sean Farley avatar Delon R. Newman avatar Józef Piątkiewicz avatar cxxxr avatar Alexander Artemenko avatar David.Gao avatar Jeremy Field avatar Indraniel avatar Stefan Eletzhofer avatar  avatar Neirac avatar latrokles avatar  avatar  avatar  avatar Willem Rein Oudshoorn avatar

Watchers

 avatar James Cloos avatar  avatar Jeremy Field avatar  avatar

cl-nextstep's Issues

Error when I try to do (ql:quickload "cl-nextstep") on M1 macOS (SBCL)

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.

Trivial contribution

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.