Created
August 17, 2011 03:29
-
-
Save rramsden/1150756 to your computer and use it in GitHub Desktop.
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
private static String MAIN = "/crafty.clj"; | |
private Object crafty = null; // hold onto reference for loaded clojure file | |
@Override | |
public void onLoad() { | |
// executeScript will return an instance of clojure.lang.Var | |
crafty = executeScript(getClass().getResourceAsStream( MAIN ), MAIN); | |
try { | |
// is there a way I can invoke "onLoad" using the `crafty` reference I've created? | |
RT.var("crafty.core", "onLoad").invoke(); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
protected Object executeScript(InputStream ins, String path) { | |
int slash = path.lastIndexOf('/'); | |
String file = slash >= 0 ? path.substring(slash + 1) : path; | |
try { | |
return Compiler.load(new InputStreamReader(ins), path, file); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
return null; | |
} | |
///////////// crafty.clj ///////////////// | |
(ns crafty.core) | |
(defn onEnable [] | |
(println "Plugin Enabled.")) | |
(defn onDisable [] | |
(println "Plugin Disabled.")) | |
(defn onLoad [] | |
(println "Plugin Loaded.")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment