CFFI wrapper for the Nuklear IM GUI library with liballegro backend, to be used with cl-liballegro.

Upstream URL


Andrew Kravchuk <>




This is CFFI wrapper for the Nuklear IM GUI library with liballegro backend, to be used with cl-liballegro.

Nuklear is minimal immediate-mode graphical user interface toolkit. To use it alongside liballegro, you have to write some amount of glue code. This library brings both Nuklear itself and that glue code to Common Lisp, so you can just plug it in and have some nice minimal GUI in your cl-liballegro-powered application.




Just execute (ql:quickload :cl-liballegro-nuklear) in your Lisp.

Note: upon loading this library with asdf, the corresponding foreign library is automatically built (allegro_nuklear.dll on Windows, on more sane operating systems), so you'll have to have compiler toolchain and liballegro dev files installed on your machine.

Currently tested to work on following OSes:

...and on following Lisp compilers:


(ql:quickload '(:cl-liballegro :cl-liballegro-nuklear :float-features))

(cffi:defcallback main :int ((argc :int) (argv :pointer))
  (al:init) (al:init-primitives-addon) (al:init-image-addon)
  (al:init-font-addon) (al:init-ttf-addon)
  (let ((display (al:create-display 800 600))
        (event-queue (al:create-event-queue)))
    (al:register-event-source event-queue (al:get-display-event-source display))
    (al:register-event-source event-queue (al:get-mouse-event-source))
    (cffi:with-foreign-object (ev '(:union al:event))
        :with font := (nk:allegro-font-create-from-file "Roboto-Regular.ttf" 12 0)
        :with ctx := (nk:allegro-init font display 800 600)
        :do (let ((get-event (al:wait-for-event-timed event-queue ev 0.06)))
              (when (and get-event
                          (cffi:foreign-slot-value ev '(:union al:event) 'al::type)
              (nk:input-begin ctx)
              (loop :while get-event
                    :do (nk:allegro-handle-event ev)
                        (setf get-event (al:get-next-event event-queue ev)))
              (nk:input-end ctx)
              (unless (zerop (nk:begin ctx "Demo" '(nk::x 50f0 nk::y 50f0 nk::w 100f0 nk::h 100f0) 0))
                (nk:layout-row-static ctx 30f0 80 1)
                (unless (zerop (nk:button-label ctx "button"))
                  (format t "button pressed~%"))
                (nk:end ctx)
           (nk:allegro-font-del font)
           (al:destroy-display display)
           (al:destroy-event-queue event-queue)
           (return 0)))))

    (:divide-by-zero :invalid :inexact :overflow :underflow)
  (al:run-main 0 (cffi:null-pointer) (cffi:callback main)))

See example.lisp for more involved example.

Note: nk:prog is renamed to nk:prog- because of obvious NAME-CONFLICT error.

There's also lispy interface making library interaction more idiomatic of CL. See docstrings in lispy.lisp for documentation.

Related projects

  • bodge-nuklear, which depends on nuklear-blob is other CFFI wrapper for Nuklear. It does not include glue code for liballegro, but designed to work with OpenGL-based cl-bodge game framework.


Merge requests are welcome. For major changes, please open an issue first to discuss what you would like to change.



Dependencies (2)

  • cffi
  • trivial-features

Dependents (0)

    • GitHub
    • Quicklisp