Browse Source

new commands, prevent termination of scripts if a wait is on the last
line

Kajetan Johannes Hammerle 4 years ago
parent
commit
a43273fc3d

+ 8 - 0
src/me/hammerle/snuviscript/code/FunctionRegistry.java

@@ -74,6 +74,14 @@ public class FunctionRegistry {
         });
         registerFunction("script.getfromid", (sc, in) -> sc.getScriptManager().getScript(in[0].getInt(sc)));
         registerFunction("script.getid", (sc, in) -> (double) ((Script) in[0].get(sc)).getId());
+        registerFunction("script.getvar", (sc, in) -> {
+            Script other = (Script) in[0].get(sc);
+            return other.getVar(in[1].getString(sc)).get(other);
+        });
+        registerConsumer("script.setvar", (sc, in) -> {
+            Script other = (Script) in[0].get(sc);
+            other.getVar(in[1].getString(sc)).set(other, in[2].get(sc));
+        });
         registerFunction("script.getall", (sc, in) -> {
             String name = in[0].getString(sc);
             return sc.getScriptManager().getScripts().stream()

+ 2 - 3
src/me/hammerle/snuviscript/code/Script.java

@@ -124,8 +124,7 @@ public final class Script {
 
             if(System.nanoTime() > endTime) {
                 isHolded = true;
-                sm.getScheduler().scheduleTask(()
-                        -> {
+                sm.getScheduler().scheduleTask(() -> {
                     if(!shouldTerm()) {
                         isHolded = false;
                         run();
@@ -265,7 +264,7 @@ public final class Script {
     }
 
     public boolean shouldTerm() {
-        return lineIndex < 0 || lineIndex >= code.length;
+        return (lineIndex < 0 || lineIndex >= code.length) && !isWaiting;
     }
 
     public void onTerm() {

+ 4 - 3
src/me/hammerle/snuviscript/test/Test.java

@@ -24,9 +24,10 @@ public class Test {
         testCompiler();
         testOutput();
         
-        LOGGER.reset();
-        PARSER.startScript(true, "test", "./test/test.test");
-        LOGGER.printAll();
+        //LOGGER.reset();
+        //PARSER.startScript(true, "test", "./test/test.test");
+        //SCHEDULER.execute();
+        //LOGGER.printAll();
     }
 
     private static void testOutput() {

+ 7 - 9
test/test.test

@@ -1,10 +1,8 @@
-nanos = 0;
-for(i = 0; i < 100; i++) {
-    nanos -= time.getNanos();
-    //wusi();
-    nanos += time.getNanos();
-}
-print(nanos / 100);
-
-function wusi() {
+c = 0;
+@loop
+c++;
+print(c);
+if(c < 40) {
+    sgoto(40, "loop");
 }
+wait();