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.show :as show]
;[ludus.draw :as d] ;[ludus.draw :as d]
#?(:cljs [cljs.reader]) #?(:cljs [cljs.reader])
#?(:cljs [goog.object :as o])
)) ))
;; TODO: make eq, and, or special forms that short-circuit ;; TODO: make eq, and, or special forms that short-circuit
@ -145,50 +146,50 @@
#?( #?(
:clj clojure.lang.Keyword :clj clojure.lang.Keyword
:cljs cljs.core/Keyword :cljs cljs.core/Keyword
) )
:long :long
#?( #?(
:clj java.lang.Long :clj java.lang.Long
:cljs js/Number :cljs js/Number
) )
:double :double
#?( #?(
:clj java.lang.Double :clj java.lang.Double
:cljs js/Number :cljs js/Number
) )
:string :string
#?( #?(
:clj java.lang.String :clj java.lang.String
:cljs js/String :cljs js/String
) )
:boolean :boolean
#?( #?(
:clj java.lang.Boolean :clj java.lang.Boolean
:cljs js/Boolean :cljs js/Boolean
) )
:set :set
#?( #?(
:clj clojure.lang.PersistentHashSet :clj clojure.lang.PersistentHashSet
:cljs cljs.core/PersistentHashSet :cljs cljs.core/PersistentHashSet
) )
:vector :vector
#?( #?(
:clj clojure.lang.PersistentVector :clj clojure.lang.PersistentVector
:cljs cljs.core/PersistentVector :cljs cljs.core/PersistentVector
) )
:map :map
#?( #?(
:clj clojure.lang.PersistentArrayMap :clj clojure.lang.PersistentArrayMap
:cljs cljs.core/PersistentArrayMap :cljs cljs.core/PersistentArrayMap
) )
}) })
(defn get-type [value] (defn get-type [value]
(let [t (type value)] (let [t (type value)]
@ -232,17 +233,25 @@
#?( #?(
:clj read-string :clj read-string
:cljs cljs.reader/read-string :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" (def clj {:name "clj"
::data/type ::data/clj ::data/type ::data/clj
:body (fn [& args] :body (fn [& args]
(println "Args passed: " args) (println "Args passed: " args)
(let [called (-> args first strpart readstr eval) (let [called (-> args first strpart readstr resolve-str)
fn-args (rest args)] fn-args (rest args)]
(println "Fn: " called) (println "Fn: " called)
(println "Args: " fn-args) (println "Args: " (clj->js fn-args))
(apply called fn-args)))}) #?(
:clj(apply called fn-args)
:cljs (.apply called js/window (clj->js fn-args)))))})
(def count- {:name "count" (def count- {:name "count"
::data/type ::data/clj ::data/type ::data/clj