|
@@ -24,6 +24,7 @@ import java.util.function.BiConsumer;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.function.Predicate;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import me.hammerle.config.SnuviConfig;
|
|
|
import me.hammerle.exceptions.FileIOException;
|
|
|
import me.hammerle.exceptions.GotoLabelNotFoundException;
|
|
|
import me.hammerle.exceptions.PreScriptException;
|
|
@@ -116,40 +117,31 @@ public class SnuviParser
|
|
|
// bit
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
|
|
- registerFunction("bit.rightshiftn", (args, qd) ->
|
|
|
- ((Fraction) args[0]).rightShiftNumerator(getInt(args[1])));
|
|
|
- registerFunction("bit.rightshiftd", (args, qd) ->
|
|
|
- ((Fraction) args[0]).rightShiftDenominator(getInt(args[1])));
|
|
|
- registerFunction("bit.leftshiftn", (args, qd) ->
|
|
|
- ((Fraction) args[0]).leftShiftNumerator(getInt(args[1])));
|
|
|
- registerFunction("bit.leftshiftd", (args, qd) ->
|
|
|
- ((Fraction) args[0]).leftShiftDenominator(getInt(args[1])));
|
|
|
- registerFunction("bit.and", (args, qd) ->
|
|
|
+ registerFunction(">>", (args, qd) ->
|
|
|
+ ((Fraction) args[0]).rightShift(getInt(args[1])));
|
|
|
+ registerFunction("<<", (args, qd) ->
|
|
|
+ ((Fraction) args[0]).leftShift(getInt(args[1])));
|
|
|
+ registerFunction("&", (args, qd) ->
|
|
|
((Fraction) args[0]).and((Fraction) args[1]));
|
|
|
- registerFunction("bit.or", (args, qd) ->
|
|
|
+ registerFunction("|", (args, qd) ->
|
|
|
((Fraction) args[0]).or((Fraction) args[1]));
|
|
|
- registerFunction("bit.xor", (args, qd) ->
|
|
|
+ registerFunction("^", (args, qd) ->
|
|
|
((Fraction) args[0]).xor((Fraction) args[1]));
|
|
|
- registerFunction("bit.invert", (args, qd) ->
|
|
|
- ((Fraction) args[0]).invert());
|
|
|
- registerFunction("bit.setn", (args, qd) ->
|
|
|
- ((Fraction) args[0]).setNumeratorBit(getInt(args[1])));
|
|
|
- registerFunction("bit.setd", (args, qd) ->
|
|
|
- ((Fraction) args[0]).setDenominatorBit(getInt(args[1])));
|
|
|
- registerFunction("bit.unsetn", (args, qd) ->
|
|
|
- ((Fraction) args[0]).unsetNumeratorBit(getInt(args[1])));
|
|
|
- registerFunction("bit.unsetd", (args, qd) ->
|
|
|
- ((Fraction) args[0]).unsetDenominatorBit(getInt(args[1])));
|
|
|
- registerFunction("bit.getn", (args, qd) ->
|
|
|
- ((Fraction) args[0]).getNumeratorBit(getInt(args[1])));
|
|
|
- registerFunction("bit.getd", (args, qd) ->
|
|
|
- ((Fraction) args[0]).getDenominatorBit(getInt(args[1])));
|
|
|
+ registerFunction("~", (args, qd) ->
|
|
|
+ ((Fraction) args[0]).invertBits());
|
|
|
+ registerFunction("bit.set", (args, qd) ->
|
|
|
+ ((Fraction) args[0]).setBit(getInt(args[1])));
|
|
|
+ registerFunction("bit.unset", (args, qd) ->
|
|
|
+ ((Fraction) args[0]).unsetBit(getInt(args[1])));
|
|
|
+ registerFunction("bit.get", (args, qd) ->
|
|
|
+ ((Fraction) args[0]).getBit(getInt(args[1])));
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
// math
|
|
|
// -------------------------------------------------------------------------------
|
|
|
- registerFunction("math.mod", (args, sc) ->
|
|
|
+ registerFunction("%", (args, sc) ->
|
|
|
new Fraction(getInt(args[0]) % getInt(args[1])));
|
|
|
+ registerAlias("math.mod", "%");
|
|
|
registerFunction("math.abs", (args, sc) ->
|
|
|
((Fraction) args[0]).abs());
|
|
|
registerFunction("math.pow", (args, sc) ->
|
|
@@ -175,7 +167,7 @@ public class SnuviParser
|
|
|
registerFunction("math.ln", (args, sc) ->
|
|
|
((Fraction) args[0]).log());
|
|
|
registerFunction("math.log", (args, sc) ->
|
|
|
- ((Fraction) args[0]).log());
|
|
|
+ ((Fraction) args[0]).log10());
|
|
|
registerFunction("math.random", (args, sc) ->
|
|
|
new Fraction(ScriptUtils.randomInt(getInt(args[0]), getInt(args[1]))));
|
|
|
registerFunction("math.round", (args, sc) ->
|
|
@@ -222,27 +214,28 @@ public class SnuviParser
|
|
|
// -------------------------------------------------------------------------------
|
|
|
// arrays
|
|
|
// -------------------------------------------------------------------------------
|
|
|
- registerConsumer("array.new", (args, sc) ->
|
|
|
- sc.setVar(args[0].toString(), new Object[ScriptUtils.getInt(args[1])]));
|
|
|
- registerConsumer("array.set", (args, sc) ->
|
|
|
+ /*registerConsumer("array.new", (args, sc) ->
|
|
|
+ sc.setVar(args[0].toString(), new Object[ScriptUtils.getInt(args[1])]));
|
|
|
+ registerConsumer("array.=", (args, sc) ->
|
|
|
((Object[]) sc.getVar(args[0].toString()))[ScriptUtils.getInt(args[1])] = args[2]);
|
|
|
+ registerAlias("array.set", "array.=");
|
|
|
registerFunction("array.get", (args, sc) ->
|
|
|
((Object[]) sc.getVar(args[0].toString()))[ScriptUtils.getInt(args[1])]);
|
|
|
- registerFunction("array.inc", (args, sc) ->
|
|
|
+ registerFunction("array.++", (args, sc) ->
|
|
|
{
|
|
|
Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
int i = ScriptUtils.getInt(args[1]);
|
|
|
o[i] = ((Fraction) o[i]).add(new Fraction(1));
|
|
|
return o[i];
|
|
|
});
|
|
|
- registerFunction("array.dec", (args, sc) ->
|
|
|
+ registerFunction("array.--", (args, sc) ->
|
|
|
{
|
|
|
Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
int i = ScriptUtils.getInt(args[1]);
|
|
|
o[i] = ((Fraction) o[i]).sub(new Fraction(1));
|
|
|
return o[i];
|
|
|
});
|
|
|
- registerFunction("array.postinc", (args, sc) ->
|
|
|
+ registerFunction("array.p+", (args, sc) ->
|
|
|
{
|
|
|
Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
int i = ScriptUtils.getInt(args[1]);
|
|
@@ -250,7 +243,7 @@ public class SnuviParser
|
|
|
o[i] = f.add(new Fraction(1));
|
|
|
return f;
|
|
|
});
|
|
|
- registerFunction("array.postdec", (args, sc) ->
|
|
|
+ registerFunction("array.p-", (args, sc) ->
|
|
|
{
|
|
|
Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
int i = ScriptUtils.getInt(args[1]);
|
|
@@ -258,32 +251,68 @@ public class SnuviParser
|
|
|
o[i] = f.sub(new Fraction(1));
|
|
|
return f;
|
|
|
});
|
|
|
- registerConsumer("array.add", (args, sc) ->
|
|
|
+ registerConsumer("array.+=", (args, sc) ->
|
|
|
{
|
|
|
Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
int i = ScriptUtils.getInt(args[1]);
|
|
|
o[i] = ((Fraction) o[i]).add((Fraction) args[2]);
|
|
|
});
|
|
|
- registerConsumer("array.sub", (args, sc) ->
|
|
|
+ registerConsumer("array.-=", (args, sc) ->
|
|
|
{
|
|
|
Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
int i = ScriptUtils.getInt(args[1]);
|
|
|
o[i] = ((Fraction) o[i]).sub((Fraction) args[2]);
|
|
|
});
|
|
|
- registerConsumer("array.mul", (args, sc) ->
|
|
|
+ registerConsumer("array.*=", (args, sc) ->
|
|
|
{
|
|
|
Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
int i = ScriptUtils.getInt(args[1]);
|
|
|
o[i] = ((Fraction) o[i]).mul((Fraction) args[2]);
|
|
|
});
|
|
|
- registerConsumer("array.div", (args, sc) ->
|
|
|
+ registerConsumer("array./=", (args, sc) ->
|
|
|
{
|
|
|
Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
int i = ScriptUtils.getInt(args[1]);
|
|
|
o[i] = ((Fraction) o[i]).div((Fraction) args[2]);
|
|
|
});
|
|
|
+ registerConsumer("array.%=", (args, sc) ->
|
|
|
+ {
|
|
|
+ Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
+ int i = ScriptUtils.getInt(args[1]);
|
|
|
+ o[i] = ScriptUtils.getInt(o[i]) % ScriptUtils.getInt(args[2]);
|
|
|
+ });
|
|
|
+ registerConsumer("array.<<=", (args, sc) ->
|
|
|
+ {
|
|
|
+ Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
+ int i = ScriptUtils.getInt(args[1]);
|
|
|
+ o[i] = ((Fraction) o[i]).leftShift(ScriptUtils.getInt(args[2]));
|
|
|
+ });
|
|
|
+ registerConsumer("array.>>=", (args, sc) ->
|
|
|
+ {
|
|
|
+ Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
+ int i = ScriptUtils.getInt(args[1]);
|
|
|
+ o[i] = ((Fraction) o[i]).rightShift(ScriptUtils.getInt(args[2]));
|
|
|
+ });
|
|
|
+ registerConsumer("array.&=", (args, sc) ->
|
|
|
+ {
|
|
|
+ Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
+ int i = ScriptUtils.getInt(args[1]);
|
|
|
+ o[i] = ((Fraction) o[i]).and((Fraction) args[2]);
|
|
|
+ });
|
|
|
+ registerConsumer("array.^=", (args, sc) ->
|
|
|
+ {
|
|
|
+ Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
+ int i = ScriptUtils.getInt(args[1]);
|
|
|
+ o[i] = ((Fraction) o[i]).xor((Fraction) args[2]);
|
|
|
+ });
|
|
|
+ registerConsumer("array.|=", (args, sc) ->
|
|
|
+ {
|
|
|
+ Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
+ int i = ScriptUtils.getInt(args[1]);
|
|
|
+ o[i] = ((Fraction) o[i]).or((Fraction) args[2]);
|
|
|
+ });
|
|
|
registerFunction("array.getsize", (args, sc) ->
|
|
|
- ((Object[]) args[0]).length);
|
|
|
+ new Fraction(((Object[]) args[0]).length));
|
|
|
registerConsumer("array.swap", (args, sc) ->
|
|
|
{
|
|
|
Object[] o = (Object[]) args[0];
|
|
@@ -332,7 +361,7 @@ public class SnuviParser
|
|
|
{
|
|
|
Arrays.fill((Object[]) args[0], ScriptUtils.getInt(args[2]), ScriptUtils.getInt(args[3]), args[1]);
|
|
|
}
|
|
|
- });
|
|
|
+ });*/
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
@@ -343,21 +372,23 @@ public class SnuviParser
|
|
|
registerFunction("map.exists", (args, sc) ->
|
|
|
args[0] instanceof Map);
|
|
|
registerConsumer("map.add", (args, sc) ->
|
|
|
- ((HashMap) args[0]).put(args[1], args[2]));
|
|
|
+ ((Map) args[0]).put(args[1], args[2]));
|
|
|
registerConsumer("map.remove", (args, sc) ->
|
|
|
- ((HashMap) args[0]).remove(args[1]));
|
|
|
+ ((Map) args[0]).remove(args[1]));
|
|
|
registerFunction("map.contains", (args, sc) ->
|
|
|
- ((HashMap) args[0]).containsKey(args[1]));
|
|
|
+ ((Map) args[0]).containsKey(args[1]));
|
|
|
registerFunction("map.getsize", (args, sc) ->
|
|
|
- new Fraction(((HashMap) args[0]).size()));
|
|
|
+ new Fraction(((Map) args[0]).size()));
|
|
|
registerFunction("map.get", (args, sc) ->
|
|
|
- ((HashMap) args[0]).get(args[1]));
|
|
|
+ ((Map) args[0]).get(args[1]));
|
|
|
+ registerFunction("map.getordefault", (args, sc) ->
|
|
|
+ ((Map) args[0]).getOrDefault(args[1], args[2]));
|
|
|
registerConsumer("map.clear", (args, sc) ->
|
|
|
- ((HashMap) args[0]).clear());
|
|
|
+ ((Map) args[0]).clear());
|
|
|
registerConsumer("map.keys", (args, sc) ->
|
|
|
- sc.setVar(args[0].toString(), ((HashMap) args[1]).keySet().stream().collect(Collectors.toList())));
|
|
|
+ sc.setVar(args[0].toString(), ((Map) args[1]).keySet().stream().collect(Collectors.toList())));
|
|
|
registerConsumer("map.values", (args, sc) ->
|
|
|
- sc.setVar(args[0].toString(), ((HashMap) args[1]).values().stream().collect(Collectors.toList())));
|
|
|
+ sc.setVar(args[0].toString(), ((Map) args[1]).values().stream().collect(Collectors.toList())));
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
// sets
|
|
@@ -367,15 +398,15 @@ public class SnuviParser
|
|
|
registerFunction("set.exists", (args, sc) ->
|
|
|
args[0] instanceof Set);
|
|
|
registerConsumer("set.add", (args, sc) ->
|
|
|
- ((HashSet) args[0]).add(args[1]));
|
|
|
+ ((Set) args[0]).add(args[1]));
|
|
|
registerConsumer("set.remove", (args, sc) ->
|
|
|
- ((HashSet) args[0]).remove(args[1]));
|
|
|
+ ((Set) args[0]).remove(args[1]));
|
|
|
registerFunction("set.contains", (args, sc) ->
|
|
|
- ((HashSet) args[0]).contains(args[1]));
|
|
|
+ ((Set) args[0]).contains(args[1]));
|
|
|
registerFunction("set.getsize", (args, sc) ->
|
|
|
- new Fraction(((HashSet) args[0]).size()));
|
|
|
+ new Fraction(((Set) args[0]).size()));
|
|
|
registerConsumer("set.tolist", (args, sc) ->
|
|
|
- sc.setVar(args[0].toString(), ((HashSet) args[1]).stream().collect(Collectors.toList())));
|
|
|
+ sc.setVar(args[0].toString(), ((Set) args[1]).stream().collect(Collectors.toList())));
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
// time
|
|
@@ -400,6 +431,8 @@ public class SnuviParser
|
|
|
// -------------------------------------------------------------------------------
|
|
|
// text
|
|
|
// -------------------------------------------------------------------------------
|
|
|
+ registerFunction("text.matches", (args, sc) ->
|
|
|
+ args[0].toString().matches(args[1].toString()));
|
|
|
registerFunction("text.number", (args, sc) ->
|
|
|
fractionToDoubleString((Fraction) args[0]));
|
|
|
registerFunction("text.class", (args, sc) ->
|
|
@@ -450,16 +483,14 @@ public class SnuviParser
|
|
|
// files
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
|
|
- registerFunction("file.new", (args, sc) ->
|
|
|
- new File(args[0].toString()));
|
|
|
+ registerConsumer("file.new", (args, sc) ->
|
|
|
+ sc.setVar(args[0].toString(), new File(args[1].toString())));
|
|
|
registerFunction("file.exists", (args, sc) ->
|
|
|
((File) args[0]).exists());
|
|
|
registerFunction("file.delete", (args, sc) ->
|
|
|
((File) args[0]).delete());
|
|
|
registerFunction("file.getname", (args, sc) ->
|
|
|
((File) args[0]).getName());
|
|
|
- registerFunction("file.", (args, sc) ->
|
|
|
- ((File) args[0]).renameTo(new File(args[1].toString())));
|
|
|
registerConsumer("file.getlist", (args, sc) ->
|
|
|
sc.setVar(args[0].toString(), Arrays.asList(((File) args[0]).listFiles())));
|
|
|
registerConsumer("file.read", (args, sc) ->
|
|
@@ -467,33 +498,86 @@ public class SnuviParser
|
|
|
registerConsumer("file.write", (args, sc) ->
|
|
|
writeFile(args, sc));
|
|
|
|
|
|
+ // ---------------------------------------------------------------------
|
|
|
+ // config
|
|
|
+ // ---------------------------------------------------------------------
|
|
|
+
|
|
|
+ registerConsumer("config.new", (args, sc) ->
|
|
|
+ sc.setVar(args[0].toString(), new SnuviConfig(logger, args[1].toString(), args[2].toString())));
|
|
|
+ registerFunction("config.exists", (args, sc) ->
|
|
|
+ ((SnuviConfig) args[0]).exists());
|
|
|
+ registerFunction("config.save", (args, sc) ->
|
|
|
+ ((SnuviConfig) args[0]).save());
|
|
|
+ registerFunction("config.delete", (args, sc) ->
|
|
|
+ ((SnuviConfig) args[0]).delete());
|
|
|
+ registerConsumer("config.set", (args, sc) ->
|
|
|
+ ((SnuviConfig) args[0]).set(args[1].toString(), args[2]));
|
|
|
+ registerFunction("config.getbool", (args, sc) ->
|
|
|
+ ((SnuviConfig) args[0]).getBoolean(args[1].toString(), args[2] == null ? null : (boolean) args[2]));
|
|
|
+ registerFunction("config.getfraction", (args, sc) ->
|
|
|
+ ((SnuviConfig) args[0]).getFraction(args[1].toString(), (Fraction) args[2]));
|
|
|
+ registerFunction("config.getstring", (args, sc) ->
|
|
|
+ ((SnuviConfig) args[0]).getString(args[1].toString(), args[2] == null ? null : args[2].toString()));
|
|
|
+
|
|
|
// -------------------------------------------------------------------------------
|
|
|
// commands without library
|
|
|
// -------------------------------------------------------------------------------
|
|
|
- registerFunction("add", (args, sc) ->
|
|
|
+ registerFunction("+", (args, sc) ->
|
|
|
((Fraction) args[0]).add((Fraction) args[1]));
|
|
|
- registerFunction("sub", (args, sc) ->
|
|
|
+ registerAlias("add", "+");
|
|
|
+ registerFunction("-", (args, sc) ->
|
|
|
((Fraction) args[0]).sub((Fraction) args[1]));
|
|
|
- registerConsumer("addvar", (args, sc) ->
|
|
|
+ registerAlias("sub", "-");
|
|
|
+ registerConsumer("+=", (args, sc) ->
|
|
|
{
|
|
|
String s = args[0].toString();
|
|
|
sc.setVar(s, ((Fraction) sc.getVar(s)).add((Fraction) args[1]));
|
|
|
});
|
|
|
- registerConsumer("subvar", (args, sc) ->
|
|
|
+ registerConsumer("-=", (args, sc) ->
|
|
|
{
|
|
|
String s = args[0].toString();
|
|
|
sc.setVar(s, ((Fraction) sc.getVar(s)).sub((Fraction) args[1]));
|
|
|
});
|
|
|
- registerConsumer("mulvar", (args, sc) ->
|
|
|
+ registerConsumer("*=", (args, sc) ->
|
|
|
{
|
|
|
String s = args[0].toString();
|
|
|
sc.setVar(s, ((Fraction) sc.getVar(s)).mul((Fraction) args[1]));
|
|
|
});
|
|
|
- registerConsumer("divvar", (args, sc) ->
|
|
|
+ registerConsumer("/=", (args, sc) ->
|
|
|
{
|
|
|
String s = args[0].toString();
|
|
|
sc.setVar(s, ((Fraction) sc.getVar(s)).div((Fraction) args[1]));
|
|
|
});
|
|
|
+ registerConsumer("%=", (args, sc) ->
|
|
|
+ {
|
|
|
+ String s = args[0].toString();
|
|
|
+ sc.setVar(s, ScriptUtils.getInt(sc.getVar(s)) % ScriptUtils.getInt(args[1]));
|
|
|
+ });
|
|
|
+ registerConsumer("<<=", (args, sc) ->
|
|
|
+ {
|
|
|
+ String s = args[0].toString();
|
|
|
+ sc.setVar(s, ((Fraction) sc.getVar(s)).leftShift(ScriptUtils.getInt(args[1])));
|
|
|
+ });
|
|
|
+ registerConsumer(">>=", (args, sc) ->
|
|
|
+ {
|
|
|
+ String s = args[0].toString();
|
|
|
+ sc.setVar(s, ((Fraction) sc.getVar(s)).rightShift(ScriptUtils.getInt(args[1])));
|
|
|
+ });
|
|
|
+ registerConsumer("&=", (args, sc) ->
|
|
|
+ {
|
|
|
+ String s = args[0].toString();
|
|
|
+ sc.setVar(s, ((Fraction) sc.getVar(s)).and((Fraction) args[1]));
|
|
|
+ });
|
|
|
+ registerConsumer("^=", (args, sc) ->
|
|
|
+ {
|
|
|
+ String s = args[0].toString();
|
|
|
+ sc.setVar(s, ((Fraction) sc.getVar(s)).xor((Fraction) args[1]));
|
|
|
+ });
|
|
|
+ registerConsumer("|=", (args, sc) ->
|
|
|
+ {
|
|
|
+ String s = args[0].toString();
|
|
|
+ sc.setVar(s, ((Fraction) sc.getVar(s)).or((Fraction) args[1]));
|
|
|
+ });
|
|
|
registerFunction("inc", (args, sc) ->
|
|
|
{
|
|
|
String s = args[0].toString();
|
|
@@ -501,6 +585,7 @@ public class SnuviParser
|
|
|
sc.setVar(s, n);
|
|
|
return n;
|
|
|
});
|
|
|
+ registerAlias("++", "inc");
|
|
|
registerFunction("dec", (args, sc) ->
|
|
|
{
|
|
|
String s = args[0].toString();
|
|
@@ -508,28 +593,32 @@ public class SnuviParser
|
|
|
sc.setVar(s, n);
|
|
|
return n;
|
|
|
});
|
|
|
- registerFunction("postinc", (args, sc) ->
|
|
|
+ registerAlias("--", "dec");
|
|
|
+ registerFunction("p+", (args, sc) ->
|
|
|
{
|
|
|
String s = args[0].toString();
|
|
|
Fraction n = (Fraction) sc.getVar(s);
|
|
|
sc.setVar(s, n.add(new Fraction(1)));
|
|
|
return n;
|
|
|
});
|
|
|
- registerFunction("postdec", (args, sc) ->
|
|
|
+ registerFunction("p-", (args, sc) ->
|
|
|
{
|
|
|
String s = args[0].toString();
|
|
|
Fraction n = (Fraction) sc.getVar(s);
|
|
|
sc.setVar(s, n.add(new Fraction(-1)));
|
|
|
return n;
|
|
|
});
|
|
|
- registerFunction("mul", (args, sc) ->
|
|
|
+ registerFunction("*", (args, sc) ->
|
|
|
((Fraction) args[0]).mul((Fraction) args[1]));
|
|
|
- registerFunction("div", (args, sc) ->
|
|
|
+ registerAlias("mul", "*");
|
|
|
+ registerFunction("/", (args, sc) ->
|
|
|
((Fraction) args[0]).div((Fraction) args[1]));
|
|
|
+ registerAlias("div", "/");
|
|
|
registerFunction("getvar", (args, sc) ->
|
|
|
sc.getVar(args[0].toString()));
|
|
|
registerConsumer("setvar", (args, sc) ->
|
|
|
sc.setVar(args[0].toString(), args[1]));
|
|
|
+ registerAlias("=", "setvar");
|
|
|
registerConsumer("removevar", (args, sc) ->
|
|
|
sc.removeVar(args[0].toString()));
|
|
|
registerConsumer("reset", (args, sc) ->
|
|
@@ -539,7 +628,7 @@ public class SnuviParser
|
|
|
|
|
|
// branching
|
|
|
registerConsumer("goto", (args, sc) ->
|
|
|
- sc.gotoLabel(args[0].toString(), false));
|
|
|
+ sc.gotoLabel(args[0].toString(), false, true));
|
|
|
registerConsumer("sgoto", (args, sc) ->
|
|
|
scheduleGoto(args, sc));
|
|
|
registerConsumer("gosub", (args, sc) ->
|
|
@@ -589,25 +678,34 @@ public class SnuviParser
|
|
|
});
|
|
|
registerConsumer("continue", (args, sc) ->
|
|
|
sc.jump());
|
|
|
- registerFunction("equal", (args, sc) ->
|
|
|
+ registerFunction("==", (args, sc) ->
|
|
|
isEqual(args));
|
|
|
- registerAlias("equals", "equal");
|
|
|
- registerFunction("less", (args, sc) ->
|
|
|
+ registerAlias("equal", "==");
|
|
|
+ registerAlias("equals", "==");
|
|
|
+ registerFunction("<", (args, sc) ->
|
|
|
((Fraction) args[0]).compareTo((Fraction) args[1]) < 0);
|
|
|
- registerFunction("greater", (args, sc) ->
|
|
|
+ registerAlias("less", "<");
|
|
|
+ registerFunction(">", (args, sc) ->
|
|
|
((Fraction) args[0]).compareTo((Fraction) args[1]) > 0);
|
|
|
- registerFunction("notequal", (args, sc) ->
|
|
|
+ registerAlias("greater", ">");
|
|
|
+ registerFunction("!=", (args, sc) ->
|
|
|
!isEqual(args));
|
|
|
- registerFunction("lessequal", (args, sc) ->
|
|
|
+ registerAlias("notequal", "!=");
|
|
|
+ registerFunction("<=", (args, sc) ->
|
|
|
((Fraction) args[0]).compareTo((Fraction) args[1]) <= 0);
|
|
|
- registerFunction("greaterequal", (args, sc) ->
|
|
|
+ registerAlias("lessequal", "<=");
|
|
|
+ registerFunction(">=", (args, sc) ->
|
|
|
((Fraction) args[0]).compareTo((Fraction) args[1]) >= 0);
|
|
|
- registerFunction("invert", (args, sc) ->
|
|
|
+ registerAlias("greaterequal", ">=");
|
|
|
+ registerFunction("!", (args, sc) ->
|
|
|
!((boolean) args[0]));
|
|
|
- registerFunction("and", (args, sc) ->
|
|
|
+ registerAlias("invert", "!");
|
|
|
+ registerFunction("&&", (args, sc) ->
|
|
|
Arrays.stream(args).allMatch(s -> s.equals(true)));
|
|
|
- registerFunction("or", (args, sc) ->
|
|
|
+ registerAlias("and", "&&");
|
|
|
+ registerFunction("||", (args, sc) ->
|
|
|
Arrays.stream(args).anyMatch(s -> s.equals(true)));
|
|
|
+ registerAlias("or", "||");
|
|
|
registerConsumer("waitfor", (args, sc) ->
|
|
|
waitFor(args, sc));
|
|
|
registerConsumer("term", (args, sc) ->
|
|
@@ -620,6 +718,14 @@ public class SnuviParser
|
|
|
sc.setVar(first, sc.getVar(sec));
|
|
|
sc.setVar(sec, helper);
|
|
|
});
|
|
|
+ registerFunction("islong", (args, sc) ->
|
|
|
+ {
|
|
|
+ if(args[0] instanceof Fraction)
|
|
|
+ {
|
|
|
+ return ((Fraction) args[0]).isLong();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@@ -758,6 +864,7 @@ public class SnuviParser
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressWarnings(value = "unchecked")
|
|
|
public <T extends Script> T startScript(Class<T> c, String scriptName, String code, boolean b, Object... o)
|
|
|
{
|
|
|
try
|
|
@@ -898,7 +1005,7 @@ public class SnuviParser
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
- sc.gotoLabel(args[1].toString(), true);
|
|
|
+ sc.gotoLabel(args[1].toString(), true, true);
|
|
|
sc.runCode();
|
|
|
}
|
|
|
catch(Exception ex)
|
|
@@ -962,6 +1069,7 @@ public class SnuviParser
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressWarnings(value = "unchecked")
|
|
|
private void writeFile(Object[] args, Script sc)
|
|
|
{
|
|
|
try
|
|
@@ -982,7 +1090,8 @@ public class SnuviParser
|
|
|
throw new FileIOException(ex.getMessage());
|
|
|
}
|
|
|
}
|
|
|
- Files.write(Paths.get(f.toURI()), (List) args[1], StandardCharsets.UTF_8);
|
|
|
+ Files.write(Paths.get(f.toURI()), ((List<Object>) args[1])
|
|
|
+ .stream().map(o -> String.valueOf(o)).collect(Collectors.toList()), StandardCharsets.UTF_8);
|
|
|
}
|
|
|
catch(UnsupportedOperationException | SecurityException | IOException ex)
|
|
|
{
|