(in-package :cl-tty.slot) (defvar *slots* (make-hash-table :test #'equal) "Hash table mapping slot name (string) -> list of (order . render-fn) pairs.") (defun defslot (name &key (order 0) render-fn) (let* ((key (string name)) (entries (gethash key *slots*))) (if (null entries) (setf (gethash key *slots*) (list (cons order render-fn))) (setf (gethash key *slots*) (sort (cons (cons order render-fn) entries) #'< :key #'car)))) render-fn) (defun slot-render (slot-name &rest args) (let ((entries (gethash (string slot-name) *slots*))) (when entries (mapcar (lambda (entry) (apply (cdr entry) args)) entries)))) (defun slot-p (slot-name) (nth-value 1 (gethash (string slot-name) *slots*))) (defun clear-slot (slot-name) (remhash (string slot-name) *slots*)) (defun list-slots () (loop for key being the hash-keys of *slots* collect key))