Fix clj (extern call) for js

This commit is contained in:
Scott Richmond 2023-11-25 14:26:00 -05:00
parent a072191081
commit fd77e1ed45
2 changed files with 24 additions and 13 deletions

2
src/ludus/draw.cljs Normal file
View File

@ -0,0 +1,2 @@
(ns ludus.draw)

View File

@ -4,6 +4,7 @@
[ludus.show :as show]
;[ludus.draw :as d]
#?(:cljs [cljs.reader])
#?(:cljs [goog.object :as o])
))
;; TODO: make eq, and, or special forms that short-circuit
@ -234,15 +235,23 @@
:cljs cljs.reader/read-string
))
(defn- resolve-str [str]
#?(
:clj (eval str)
:cljs (.bind (o/get js/window str) js/window)
))
(def clj {:name "clj"
::data/type ::data/clj
:body (fn [& args]
(println "Args passed: " args)
(let [called (-> args first strpart readstr eval)
(let [called (-> args first strpart readstr resolve-str)
fn-args (rest args)]
(println "Fn: " called)
(println "Args: " fn-args)
(apply called fn-args)))})
(println "Args: " (clj->js fn-args))
#?(
:clj(apply called fn-args)
:cljs (.apply called js/window (clj->js fn-args)))))})
(def count- {:name "count"
::data/type ::data/clj