Skip to content

Instantly share code, notes, and snippets.

@rramsden
Created August 17, 2011 03:29
Show Gist options
  • Save rramsden/1150756 to your computer and use it in GitHub Desktop.
Save rramsden/1150756 to your computer and use it in GitHub Desktop.
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