Last active
December 21, 2016 06:51
-
-
Save timsgardner/06363d98cd865b8b0e64faf3dd730181 to your computer and use it in GitHub Desktop.
scene-var!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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