Clojure-Unity: Getting it to Work

Clojure in Unity is a really exciting idea. Since Clojure CLR has been around a while, it’s been theoretically possible to combine the two, but last time I looked into it the old version of Mono that Unity currently uses was too big a barrier without some work being done. Well, now that work has been done, and it’s working enough that I can have a functional REPL in Unity.

The downside is that it’s very, very early stuff right now, and requires you to have your duct tape ready to deal with the problems you’ll run into.

The biggest one I’ve run into so far is the Windows paths were broken, since the main developers seem to be working on OSX. Fortunately, there’s already been one enthusiastic Windows user, Joseph Parker, who made Parade Route for Clojure Cup 2014. And made the source code available, so I could check his changes.

static public string[] CompilationRoots = new [] {
"Assets\\Clojure\\Scripts",
"Assets\\Clojure\\Libraries",
"Assets\\Clojure\\Internal",
};

static public string pathToAssemblies = "Assets\\Clojure\\Compiled";

static public void SetupLoadPath() {
string loadPath = Path.Combine(System.Environment.CurrentDirectory, pathToAssemblies);
foreach(string path in CompilationRoots) {
loadPath += ";" + Path.Combine(System.Environment.CurrentDirectory, path);
}

System.Environment.SetEnvironmentVariable("CLOJURE_LOAD_PATH", loadPath);
Debug.Log(System.Environment.GetEnvironmentVariable("CLOJURE_LOAD_PATH"));
}

There’s still some issues with it, some of which aren’t present is parade-route, especially with the play mode in the editor. But for a pre-alpha duct-taped project it’s got a lot working already.

Posted on:

Comments are closed.