第一步 继承 并 实现
AbstractFunction (固定参数) 或 AbstractVariadicFunction(可变参数)
第二步 添加 自定义函数
AviatorEvaluator.addFunction(new AviatorStringConcatFunction());
AviatorEvaluator.addFunction(new AviatorParseNumberFunction());
=========================================================================
固定参数 如:
转数值:parseNumber(str)
public class AviatorParseNumberFunction extends AbstractFunction{
@Override
public AviatorObject call(Map<String, Object> env, AviatorObject arg1) {
.......
.......
return new AviatorDouble(........);
}
@Override
public String getName() {
return "parseNumber";
}
}
动态参数 如:
字符串拼接 :string.concat(str1, str12, str3,...)
public class AviatorStringConcatFunction extends AbstractVariadicFunction {
@Override
public AviatorObject variadicCall(Map<String, Object> env, AviatorObject... argArray) {
StringBuilder sb = new StringBuilder();
for (AviatorObject arg : argArray) {
sb.append(arg.getValue(env));
}
return new AviatorString(sb.toString());
}
@Override
public String getName() {
return "string.concat";
}
}