22 lines
646 B
Plaintext
22 lines
646 B
Plaintext
|
(local util (require :plugins.fennel-xl.util))
|
||
|
|
||
|
(local mm {})
|
||
|
|
||
|
(fn mm.__call [{: module : name} ...]
|
||
|
(let [dispatcher (. mm.dispatchers module name)
|
||
|
key (dispatcher ...)
|
||
|
method (or (. mm.methods module name key) (. mm.methods module name :default))]
|
||
|
(method ...)))
|
||
|
|
||
|
(fn mm.defmulti [dispatcher name module]
|
||
|
(util.nested-tset mm [:dispatchers module name] dispatcher)
|
||
|
(setmetatable {: module : name} mm))
|
||
|
|
||
|
(fn mm.defmethod [{: module : name} key method]
|
||
|
(util.nested-tset mm [:methods module name key] method))
|
||
|
|
||
|
(fn mm.keys [{: module : name}]
|
||
|
(icollect [key _ (pairs (or (?. mm :methods module name) []))] key))
|
||
|
|
||
|
mm
|