|
@@ -24,6 +24,7 @@ import java.util.function.BiConsumer;
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Predicate;
|
|
import java.util.function.Predicate;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
+import me.hammerle.config.SnuviConfig;
|
|
import me.hammerle.exceptions.FileIOException;
|
|
import me.hammerle.exceptions.FileIOException;
|
|
import me.hammerle.exceptions.GotoLabelNotFoundException;
|
|
import me.hammerle.exceptions.GotoLabelNotFoundException;
|
|
import me.hammerle.exceptions.PreScriptException;
|
|
import me.hammerle.exceptions.PreScriptException;
|
|
@@ -166,7 +167,7 @@ public class SnuviParser
|
|
registerFunction("math.ln", (args, sc) ->
|
|
registerFunction("math.ln", (args, sc) ->
|
|
((Fraction) args[0]).log());
|
|
((Fraction) args[0]).log());
|
|
registerFunction("math.log", (args, sc) ->
|
|
registerFunction("math.log", (args, sc) ->
|
|
- ((Fraction) args[0]).log());
|
|
|
|
|
|
+ ((Fraction) args[0]).log10());
|
|
registerFunction("math.random", (args, sc) ->
|
|
registerFunction("math.random", (args, sc) ->
|
|
new Fraction(ScriptUtils.randomInt(getInt(args[0]), getInt(args[1]))));
|
|
new Fraction(ScriptUtils.randomInt(getInt(args[0]), getInt(args[1]))));
|
|
registerFunction("math.round", (args, sc) ->
|
|
registerFunction("math.round", (args, sc) ->
|
|
@@ -213,7 +214,7 @@ public class SnuviParser
|
|
// -------------------------------------------------------------------------------
|
|
// -------------------------------------------------------------------------------
|
|
// arrays
|
|
// arrays
|
|
// -------------------------------------------------------------------------------
|
|
// -------------------------------------------------------------------------------
|
|
- registerConsumer("array.new", (args, sc) ->
|
|
|
|
|
|
+ /*registerConsumer("array.new", (args, sc) ->
|
|
sc.setVar(args[0].toString(), new Object[ScriptUtils.getInt(args[1])]));
|
|
sc.setVar(args[0].toString(), new Object[ScriptUtils.getInt(args[1])]));
|
|
registerConsumer("array.=", (args, sc) ->
|
|
registerConsumer("array.=", (args, sc) ->
|
|
((Object[]) sc.getVar(args[0].toString()))[ScriptUtils.getInt(args[1])] = args[2]);
|
|
((Object[]) sc.getVar(args[0].toString()))[ScriptUtils.getInt(args[1])] = args[2]);
|
|
@@ -311,7 +312,7 @@ public class SnuviParser
|
|
o[i] = ((Fraction) o[i]).or((Fraction) args[2]);
|
|
o[i] = ((Fraction) o[i]).or((Fraction) args[2]);
|
|
});
|
|
});
|
|
registerFunction("array.getsize", (args, sc) ->
|
|
registerFunction("array.getsize", (args, sc) ->
|
|
- ((Object[]) args[0]).length);
|
|
|
|
|
|
+ new Fraction(((Object[]) args[0]).length));
|
|
registerConsumer("array.swap", (args, sc) ->
|
|
registerConsumer("array.swap", (args, sc) ->
|
|
{
|
|
{
|
|
Object[] o = (Object[]) args[0];
|
|
Object[] o = (Object[]) args[0];
|
|
@@ -360,7 +361,7 @@ public class SnuviParser
|
|
{
|
|
{
|
|
Arrays.fill((Object[]) args[0], ScriptUtils.getInt(args[2]), ScriptUtils.getInt(args[3]), args[1]);
|
|
Arrays.fill((Object[]) args[0], ScriptUtils.getInt(args[2]), ScriptUtils.getInt(args[3]), args[1]);
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ });*/
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
// -------------------------------------------------------------------------------
|
|
@@ -371,21 +372,23 @@ public class SnuviParser
|
|
registerFunction("map.exists", (args, sc) ->
|
|
registerFunction("map.exists", (args, sc) ->
|
|
args[0] instanceof Map);
|
|
args[0] instanceof Map);
|
|
registerConsumer("map.add", (args, sc) ->
|
|
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) ->
|
|
registerConsumer("map.remove", (args, sc) ->
|
|
- ((HashMap) args[0]).remove(args[1]));
|
|
|
|
|
|
+ ((Map) args[0]).remove(args[1]));
|
|
registerFunction("map.contains", (args, sc) ->
|
|
registerFunction("map.contains", (args, sc) ->
|
|
- ((HashMap) args[0]).containsKey(args[1]));
|
|
|
|
|
|
+ ((Map) args[0]).containsKey(args[1]));
|
|
registerFunction("map.getsize", (args, sc) ->
|
|
registerFunction("map.getsize", (args, sc) ->
|
|
- new Fraction(((HashMap) args[0]).size()));
|
|
|
|
|
|
+ new Fraction(((Map) args[0]).size()));
|
|
registerFunction("map.get", (args, sc) ->
|
|
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) ->
|
|
registerConsumer("map.clear", (args, sc) ->
|
|
- ((HashMap) args[0]).clear());
|
|
|
|
|
|
+ ((Map) args[0]).clear());
|
|
registerConsumer("map.keys", (args, sc) ->
|
|
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) ->
|
|
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
|
|
// sets
|
|
@@ -395,15 +398,15 @@ public class SnuviParser
|
|
registerFunction("set.exists", (args, sc) ->
|
|
registerFunction("set.exists", (args, sc) ->
|
|
args[0] instanceof Set);
|
|
args[0] instanceof Set);
|
|
registerConsumer("set.add", (args, sc) ->
|
|
registerConsumer("set.add", (args, sc) ->
|
|
- ((HashSet) args[0]).add(args[1]));
|
|
|
|
|
|
+ ((Set) args[0]).add(args[1]));
|
|
registerConsumer("set.remove", (args, sc) ->
|
|
registerConsumer("set.remove", (args, sc) ->
|
|
- ((HashSet) args[0]).remove(args[1]));
|
|
|
|
|
|
+ ((Set) args[0]).remove(args[1]));
|
|
registerFunction("set.contains", (args, sc) ->
|
|
registerFunction("set.contains", (args, sc) ->
|
|
- ((HashSet) args[0]).contains(args[1]));
|
|
|
|
|
|
+ ((Set) args[0]).contains(args[1]));
|
|
registerFunction("set.getsize", (args, sc) ->
|
|
registerFunction("set.getsize", (args, sc) ->
|
|
- new Fraction(((HashSet) args[0]).size()));
|
|
|
|
|
|
+ new Fraction(((Set) args[0]).size()));
|
|
registerConsumer("set.tolist", (args, sc) ->
|
|
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
|
|
// time
|
|
@@ -428,6 +431,8 @@ public class SnuviParser
|
|
// -------------------------------------------------------------------------------
|
|
// -------------------------------------------------------------------------------
|
|
// text
|
|
// text
|
|
// -------------------------------------------------------------------------------
|
|
// -------------------------------------------------------------------------------
|
|
|
|
+ registerFunction("text.matches", (args, sc) ->
|
|
|
|
+ args[0].toString().matches(args[1].toString()));
|
|
registerFunction("text.number", (args, sc) ->
|
|
registerFunction("text.number", (args, sc) ->
|
|
fractionToDoubleString((Fraction) args[0]));
|
|
fractionToDoubleString((Fraction) args[0]));
|
|
registerFunction("text.class", (args, sc) ->
|
|
registerFunction("text.class", (args, sc) ->
|
|
@@ -478,16 +483,14 @@ public class SnuviParser
|
|
// files
|
|
// 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) ->
|
|
registerFunction("file.exists", (args, sc) ->
|
|
((File) args[0]).exists());
|
|
((File) args[0]).exists());
|
|
registerFunction("file.delete", (args, sc) ->
|
|
registerFunction("file.delete", (args, sc) ->
|
|
((File) args[0]).delete());
|
|
((File) args[0]).delete());
|
|
registerFunction("file.getname", (args, sc) ->
|
|
registerFunction("file.getname", (args, sc) ->
|
|
((File) args[0]).getName());
|
|
((File) args[0]).getName());
|
|
- registerFunction("file.rename", (args, sc) ->
|
|
|
|
- ((File) args[0]).renameTo(new File(args[1].toString())));
|
|
|
|
registerConsumer("file.getlist", (args, sc) ->
|
|
registerConsumer("file.getlist", (args, sc) ->
|
|
sc.setVar(args[0].toString(), Arrays.asList(((File) args[0]).listFiles())));
|
|
sc.setVar(args[0].toString(), Arrays.asList(((File) args[0]).listFiles())));
|
|
registerConsumer("file.read", (args, sc) ->
|
|
registerConsumer("file.read", (args, sc) ->
|
|
@@ -495,6 +498,27 @@ public class SnuviParser
|
|
registerConsumer("file.write", (args, sc) ->
|
|
registerConsumer("file.write", (args, sc) ->
|
|
writeFile(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
|
|
// commands without library
|
|
// -------------------------------------------------------------------------------
|
|
// -------------------------------------------------------------------------------
|
|
@@ -694,6 +718,14 @@ public class SnuviParser
|
|
sc.setVar(first, sc.getVar(sec));
|
|
sc.setVar(first, sc.getVar(sec));
|
|
sc.setVar(sec, helper);
|
|
sc.setVar(sec, helper);
|
|
});
|
|
});
|
|
|
|
+ registerFunction("islong", (args, sc) ->
|
|
|
|
+ {
|
|
|
|
+ if(args[0] instanceof Fraction)
|
|
|
|
+ {
|
|
|
|
+ return ((Fraction) args[0]).isLong();
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|