Skip to content

Instantly share code, notes, and snippets.

@timsgardner
Last active December 21, 2016 06:51
Show Gist options
  • Save timsgardner/06363d98cd865b8b0e64faf3dd730181 to your computer and use it in GitHub Desktop.
Save timsgardner/06363d98cd865b8b0e64faf3dd730181 to your computer and use it in GitHub Desktop.
scene-var!
(ns timsg.scene-var
(:refer-clojure :exclude [def])
(:use [arcadia.core])
(:require [clojure.spec :as s]
[clojure.core :as c]
[arcadia.internal.spec :as as])
(:import [UnityEngine GameObject Component]))
;; ============================================================
;; much simpler way, just uses def and vars
(defn init-def
"Returns nil if the referenced object is destroyed. Maybe that's not a great idea."
[{:keys [name init update]
:as init-spec}]
(-> (or (when-let [v (resolve name)] ;; name is fully qualified
(and (bound? v)
(when-let [v (var-get v)]
(if (instance? UnityEngine.Object v)
(obj-nil v)
v))))
(and init (init)))
(as-> ent
(if update (update ent) ent))))
(defmacro def [& args]
(let [{:keys [name] :as init-spec} (parse-def-form args)]
`(let [x# (init-def ~(update init-spec :name #(list 'quote %)))]
(def ~name x#))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment