| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 | package me.hammerle.snuviscript;import me.hammerle.code.ISnuviLogger;import me.hammerle.code.ISnuviScheduler;import me.hammerle.code.Script;import me.hammerle.code.SnuviParser;import me.hammerle.exceptions.PreScriptException;public class SnuviScript {    public static void main(String[] args)     {        ISnuviLogger logger = new ISnuviLogger()         {            @Override            public void printException(Exception ex, Script s, int line)             {                System.out.println("Exception " + ex);                System.out.println("Line: " + line);            }            @Override            public void printException(Exception ex)             {                System.out.println("Exception " + ex);            }            @Override            public void printWarning(String s)             {                System.out.println("Warning: " + s);            }            @Override            public void printInfo(String s)             {                System.out.println("Info: " + s);            }        };                SnuviParser parser = new SnuviParser(logger, new ISnuviScheduler()         {            @Override            public int scheduleTask(Runnable r)             {                System.out.println("Schedule");                return 0;            }            @Override            public int scheduleTask(Runnable r, long delay)             {                System.out.println("Schedule");                return 0;            }        });        parser.registerConsumer("debug", (o, sc) -> System.out.println(o[0]));        parser.registerConsumer("deb.ug", (o, sc) -> System.out.println(o[0]));        //parser.registerFunction("ggv", (o, sc) -> o[0]);        //parser.registerFunction("read.item", (o, sc) -> o[0]);                /*StringBuilder sb = new StringBuilder("wusi = 1;\n");        int counter = 0;        for(int i = 0; i < 1000; i++)        {            switch(counter)            {                case 0: sb.append("wusi += 1;\n"); break;                case 1: sb.append("wusi *= 2;\n"); break;                case 2: sb.append("wusi = wusi - 1;\n"); break;                case 3: sb.append("wusi /= 2;\n"); break;                case 4: sb.append("wusi += 1;\n"); break;            }            counter++;            if(counter >= 5)            {                counter = 0;            }        }        sb.append("debug(wusi);");*/                String s = "debug(\"Das ist ein test\");\n" +"if(5 < 6)\n" +"{\n" +"    debug(\"hehe\");\n" +"}\n" +"else\n" +"{\n" +"    deb.ug(\"muhahah\");\n" +"    debug(\"ich bin auch da\");\n" +"}\n" +"{\n" +"debug(\"wir sind fertig\");\n" +"}";        //System.out.println(s);        //System.out.println("___________");        //parser.startScript(Script.class, "test", sb.toString(), true);        try        {            parser.startScript("test", s);        }        catch(PreScriptException ex)        {            //ex.printStackTrace();            logger.printException(ex);        }        //parser.getScript(0).runCode();        //Fraction f = Fraction.fromDouble(Fraction.PI.doubleValue());        //Object o = Code.convertInput("32.323");        //System.out.println(o + " " + o.getClass().getSimpleName());        //System.out.println(Fraction.fromDouble(0.324234235));    }   }
 |