Advertisement
Guest User

Untitled

a guest
Jun 10th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. package com.example.ifidsadminutility;
  2.  
  3. import android.util.Log;
  4. import clojure.lang.IFn;
  5. import clojure.java.api.Clojure;
  6. import java.io.StringReader;
  7.  
  8. public class ScriptManager {
  9.     private static ScriptManager instance = null;
  10.    
  11.     public static ScriptManager getInstance() {
  12.            if(instance == null) {
  13.               instance = new ScriptManager();
  14.            }
  15.            return instance;
  16.     }
  17.    
  18.     public void runTest() {    
  19.         // Load the Clojure script -- as a side effect this initializes the runtime.
  20.         IFn read_string = Clojure.var("clojure.core", "read-string");
  21.         IFn eval = Clojure.var("clojure.core", "eval");
  22.        
  23.         String str = "(ns user) (defn foo [a b]   (str a \" \" b))";
  24.         Object strObject = read_string.invoke(str);
  25.         eval.invoke(strObject);
  26.         //TODO: Load string into the clojure runtime
  27.         //RT.loadResourceScript("foo.clj");
  28.        
  29.         IFn map = Clojure.var("clojure.core", "map");
  30.         IFn inc = Clojure.var("clojure.core", "inc");
  31.         map.invoke(inc, Clojure.read("[1 2 3]"));
  32.        
  33.         // Get a reference to the foo function.
  34.         IFn foo = Clojure.var("user", "foo");
  35.  
  36.         // Call it!
  37.         Object result = foo.invoke("\"Hi\" \"there\"");
  38.         Log.v("ScriptManager", result.toString());
  39.        
  40.        
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement