Skip to content

Releases: killme2008/aviatorscript

Aviator 4.2.6 released

19 Nov 02:11
Compare
Choose a tag to compare

Main changes:

  • Fixed NPE when compare date instances #175

Aviator 4.2.5 released

11 Oct 06:26
Compare
Choose a tag to compare

Main changes:

  • Deprecated AviatorEvaluator#exec, please use AviatorEvaluator#execute instead.
  • Function missing mechanism #170, #171, you can custom your own behaviours when calling function is not found by implement FunctionMissing interface.
  • A default function missing implementation JavaMethodReflectionFunctionMissing. With this handler, you can call any java class's public instance methods by reflection even when you don't import them. The example is here,but you have to pay performance cost(almost 3x times slower than implements custom functions).
  • New doc 调用 Java 方法和 Function Missing

Aviator 4.2.4 released

20 Sep 04:25
Compare
Choose a tag to compare

Main features:

  • Fixed #162 , long type promption error.
  • Fixed #166 , call varidic methods in java class.
  • Adds seq.array(clazz, arg1, arg2, ...) function to create an array of clazz type, seq.array(int, 1, 2, 3) for example that creates an int array new int[] {1, 2, 3}.
  • Adds annotations for importing java class methods:
    • Function for java method to set custom function name.
    • Ignore to ignore java method for importing.
    • Import annotation with new method AviatorEvaluatorInstance#importFunctions to set imported methods scope and namespace.
  • Breaking change: aviator generated bytecode version bump to Java 1.7
  • map and reduce function now support java.util.Map, the element type is Map.Entry, #164
  • Constant pool for constants(number/string etc.) to reduce CPU and memory consumption #167

Aviator 4.2.3 released

09 Sep 02:31
Compare
Choose a tag to compare
  • Fixed: AviatorEvaluator.addStaticFunctions shoud be static.
  • New feature: imports java class's instance methods by AviatorEvaluator.addInstanceFunctions(String, Class) or AviatorEvaluatorInstance#addInstanceFunctions(String, Class). For example:
AviatorEvaluator.addInstanceFunctions("s", String.class);

Then you can use all java.lang.String 's all public instance methods by passing the string instance as the first argument:

s.indexOf('hello', 'l')
s.replaceAll('hello', 'l', 'x')

Aviator 4.2.2 released

05 Sep 05:46
Compare
Choose a tag to compare

Main features:

  • Added new methods AviatorEvaluator.addStaticFunctions(namespace, clazz) and AviatorEvaluatorInstanc#addStaticFunctions(namespace, clazz) to import class public static methods as custom functions under namespace #155
  • Breaking change: the regular pattern's value is the compiled java Pattern instance, it's a string before.
  • Improve runtime exceptions.

Aviator 4.2.1 released

03 Sep 07:47
Compare
Choose a tag to compare
  1. Fixed typo: SringContextFunctionLoader.java -> SpringContextFunctionLoader
  2. Fixed NPE in tracing mode #145

Many code style,compile warnings and document errors fixed, thanks to @oldratlee contribution.

Aviator 4.2.0 released

26 May 09:42
Compare
Choose a tag to compare

Main features:

  1. Fixed closured over wrong variable in nested lambda #134
  2. Adds a new opiton Options.ALWAYS_PARSE_INTEGRAL_NUMBER_INTO_DECIMAL that will parse all integral numbers into big decimal, thanks to @aliiohs #124
  3. Adds seq.contains_key(map, key) to check if the key object is exists in a map and fixed Env#contains_key #122
  4. Adds a new feature: capture function invocation arguments into env, for example:
List<FunctionArgument> args = (List<FunctionArgument>) AviatorEvaluator
		  .execute("f = lambda(a,bc, d) -> __args__ end; f(1,2,100+2)");

The args list is retrieved from env as __args__ var,and it's a list of FunctionArgument:

[
 FunctionArgument [index=0, expression=1],  
 FunctionArgument [index=1, expression=2],
 FunctionArgument [index=2, expression=100+2]
]

This feature is useful for function invocation caching or parameter vailidation, and it's optional, if you want it, you can enable it by setting Options.CAPTURE_FUNCTION_ARGS to be true, default is false.

The argument list can also be captured in custom functions, you can get it through FunctionUtils.getFunctionArguments(env) or env.get("__args__").

Aviator 4.1.2 released

29 Jan 06:15
Compare
Choose a tag to compare

Main features:

  1. Fixed a bug in FunctionUtils#getJavaObject to retrieve java collection type such as (user.roles) #106
  2. Fixed NPE when tracing expression evaluation.
  3. Variables captured by closure should be immutable. #101
  4. Adds a new option Options.DISABLE_ASSIGNMENT to disable variable assignment.
  5. Literal expression performance issue #96
  6. New functions to create java collections
    • seq.set(x,y,z...) to create a HashSet instance from varidic arguments.
    • seq.list(x,y,z...) to create a 'ArrayList` instance from varidic arguments.
    • seq.map(k1,v1, k2, v2,...) to create a HashMap instance from varidic arguments.
    • New functions seq.add,seq.remove and seq.get to add/remove/get elements(values) from collections.
  7. seq.max(coll) and seq.min(coll) to retrieve min/max element in a sequence.
  8. min(x,y,z...) and max(x,y,z...) to retrieve min/max value from varidic arguments.
  9. identity(x) function to return the argument itself.
  10. Adds a new document 4.0 features explain.

Maven

 <dependency>
      <groupId>com.googlecode.aviator</groupId>
      <artifactId>aviator</artifactId>
      <version>4.1.2</version>
  </dependency>

Aviator 4.1.1 发布

07 Jan 03:08
Compare
Choose a tag to compare

主要改动如下:

  1. 性能优化,从简单测试来看,对比 4.1.0 有近 30% 的提升,整体性能接近 3.3.0 版本。
  2. 废弃 AviatorEvaluator.exec(exp, args...) 方法,都推荐使用 execute 方法明确传入 env map 的方式。

此版本推荐升级。

`Maven 依赖:

<dependency>
      <groupId>com.googlecode.aviator</groupId>
      <artifactId>aviator</artifactId>
      <version>4.1.1</version>
  </dependency>

Aviator 4.1.0 发布

02 Jan 03:02
Compare
Choose a tag to compare

新功能列表

  1. 支持赋值语句,可以在表达式中给变量赋值,一些例子:
    assertEquals(3, AviatorEvaluator.execute("a=1; a+2"));
    assertEquals(5, AviatorEvaluator.execute("a=3; b=2; a+b"));
    assertEquals(20.0, AviatorEvaluator.execute("a=3; b=2; c=a+b; c*4.0"));
    assertEquals(6, AviatorEvaluator.execute("square = lambda(x) -> x *2 end; square(3)"));
    assertEquals(1, AviatorEvaluator.execute("a=5;b=4.2 ; c= a > b? 1: 0; c"));
    assertEquals(6, AviatorEvaluator.execute("add_n = lambda(x) -> lambda(y) -> x + y end end ; "
        + "add_1 = add_n(1) ; " + "add_2 = add_n(2) ;" + " add_1(add_2(3))"));

可以看到处了基本类型赋值之外,还可以支持将 lambda 表达式赋值给一个变量,函数也将作为 first class 成员使用。

  1. AviatorEvaulatorInstanceAviatorEvaulator 新增方法 isExpressionCached()getExpressionCacheSize() 分别用于判断表达式是否缓存编译结果,以及返回缓存的编译表达式总数。
  2. AbstractFunctionAbstractVariadicFunction 都继承了 AviatorObject,函数作为 first class 成员提供,他们的值就是自身。
  3. 新增可变参数函数 tuple(x, y, z, ...) 用于返回一个 Object [] 数组,适用于需要返回多参数的场景。
  4. 对于 a.b.c 的嵌套访问语法糖做了性能改进,如果 ab 都是 Map,将直接访问,避免全局锁和反射,感谢阿里同事的 idea 贡献。性能测试来看有接近一倍的提升。
  5. 一些代码重构和改进,感谢 @einverne

Bug 修复

  1. #77 开启高精度计算情况下,正则表达式错误。
  2. #87 longdouble 函数不支持 decimal 和 bigint 类型。
  3. #92 转义符号处理异常。
  4. 修复编译优化丢失 env 的 bug。

兼容问题

  1. FunctionUtils#getStringValue(AviatorObject, Map) 当 string 为 null 的时候直接返回,不再抛出异常 #67
  2. 4.0.0-RC 版本为了支持 lambda 闭包,引入了嵌套 scope 的概念,并且不再直接修改用户传入的 env map,但是发现很多用户依赖这个修改行为,因此 4.1.0 引入了 Options.USE_USER_ENV_AS_TOP_ENV_DIRECTLY 选项,默认为 true,表示将直接使用用户的 env 作为 top 级别的 env 使用,兼容老版本的行为 #74 #94

推荐跳过此版本,直接升级到最新版本,此版本有一定性能问题

Maven 依赖:

<dependency>
      <groupId>com.googlecode.aviator</groupId>
      <artifactId>aviator</artifactId>
      <version>4.1.0</version>
  </dependency>