Bot releases are hidden (Show)
Published by killme2008 about 4 years ago
Thit is a major version release, it introduces some new syntax features,main changes as below:
catch
clause, for example:try {
## do something
} catch (IllegalStateException | ArrayIndexOutOfBoundsException | java.io.IOException e) {
pst(e); ##print stack trace
}
It's the same as the Java 7 catch multiple exceptions.
let name = "aviator";
let a = 1;
let b = 2;
let s = "hello, #{name}, #{a} + #{b} = #{a + b}";
p(s);
It will output the string hello,avitor,1 + 2 = 3
. The expression quoted by #{}
will be executed and sticked into the result string.
A new feature Feature.StringInterpolation
is added into Feature enum, it's enabled by default.
AviatorEvaluatorInstance#validate(script)
to validate whether a text string is a legal script.nil
argument:nil =~/[a-zA-Z]+/; ## returns false when matching nil with regular pattern .
count(nil); ## returns 0
include(nil, element); ## returns false
map(nil, lambda); ## returns nil
sort(nil); ## returns nil
reduce(nil, lambda, init); ## returns the init value
filter(nil, lambda); ## returns nil
seq.every(nil, lambda); ## returns true
seq.not_any(nil, lambda); ## returns true
seq.some(nil, lambda); ## returns nil
There are some breaking changes, the user MUST note them.
Published by killme2008 over 4 years ago
Main changes:
Opitons.CAPTURE_FUNCTION_ARGS
) are wrong when invoking more than one functions.#236Options.ALWAYS_PARSE_INTEGRAL_NUMBER_INTO_DECIMAL
#237eval(script, [bindings], [cached])
to execute a script text string with binding map in scripts.reader(input_stream, [charset])
and writer(output_stream, [charset])
to IO module.Published by killme2008 over 4 years ago
Deprecated, please use 5.2.6 and above versions.
I am happy to announce that AviatorScript 5.0.0 is released. Main changes since 5.0.0-RC2:
com.googlecode.aviator.Main
to execute aviator scripts.count(nil)
returns 0 instead of throwing an exception.AviatorFunction
extends java Runnable
and Callable
interface, now you can pass a aviator function to Thread
constructor:let t = new Thread(lambda() -> p('run'); end);
start(t);
try
statement can't only be with finally
without catch
statements.Published by killme2008 over 4 years ago
Main changes:
new Class(args)
statement to create an instance of special class with arguments, for example:let s = new String("test");
p(type(s)); ## print string
throw exception
statement to throw an exception.try
/catch
/finally
statement to handle exceptions, for example: try {
throw "an exception";
} catch(e) {
pst(e);
} finally {
p("finally");
}
Opitons.MAX_LOOP_COUNT
.seq.get
to support List
.AviatorEvaluatorInstance#aliasFunction(name, alias)
to alias a function.pst(e)
to print stacktrace of an exception.println
to p
.let a = if(true) {
2
};
p(a); ## print 2
x == y
or x !=y
doesn't throw an exception any more but returns false.Published by killme2008 over 4 years ago
Main changes since 5.0.0-beta2:
Options. MAX_LOOP_COUNT
to control max loop count in for/while/sequence-iterate loop, default zero means no limitation.__MODULE__.exports
can't be assigned.seq.get
supports java.util.Set
, return the element itself if it is in set, otherwise returns nil.AviatorEvaluatorInstance#clearExpressionCache()
.AviatorEvaluatorInstance#setAviatorClassLoader(classloader)
AviatorEvaluatorInstance#useLRUExpressionCache(capacity)
.Serializable
interface #209BeanUtilsBean.getInstance
by a bean cache. #222Invocable
and refactor script engine, see the programming doc.Options.FEATURE_SET
to set engine's syntax feature, valid features are listed in Feature enum.Default set is full feature set.seq.entry(key, value)
to create a Map.Entry
.into(to_coll, from_coll)
to add all elements in from_coll
into to_coll
by seq.add(to_coll, element)
.bigint(x)
to cast a value into bigint type.decimal(x)
to cast a value into decimal type.Options.ALWAYS_USE_DOUBLE_AS_DECIMAL
, already replaced by Options. ALWAYS_USE_DECIMAL_AS_FLOATING_POINT_NUMBER
.Options.TRACE
, not supported any more.Options.DISABLE_ASSIGNMENT
, please use feature API.setOption(Options.FEATURE_SET, Feature.getCompatibleFeatures())
, then the engine only supports assignment, lambda and internal variables, if/for/while/let
etc. features are disabled.Published by killme2008 over 4 years ago
Main changes:
AviatorEvaluatorInstance#addModule
to register custom modules.let s = "hello";
for c in s {
println(c);
}
println(filter(s, seq.eq('l')));
type(x)
to return x's type, is_def(x)
returns true when variable x is defined, undef(x)
to forgot a defined variable.include(seq, x)
is O(1) time complexity for java.util.Set
now #214Published by killme2008 over 4 years ago
Since 5.0.0, aviator becomes a general-purpose scripting language, new features:
• Lexical scope by { }
• return
statement to return a value in a function or script.
• if/elsif/else
statement
• for
loop statement and supports break
, continue
• while
loop statement
• let
to define lexical variable
• fn
syntax to define named function
• ## a comment
for single line comment
Please see the documents AviatorScript UserGuide (in progress).
Breaking changes: TODO
You can try the examples by running RunScriptExample. All the examples are under examples folder.
Published by killme2008 over 4 years ago
Main changes:
AviatorEvaluator.newEnv(k1, v1, k2, v2, ...)
to create an environment map.bean.x = y
.Options.ALWAYS_PARSE_FLOATING_POINT_NUM
#191\r
or \r\n
) breaker in expression. #191m = seq.map('square', lambda(x)-> x*x end);
m.square(100.0)
Published by killme2008 almost 5 years ago
Main changes:
getVariableNames
result contains true/false/nil, #186x[i]=y
#187Published by killme2008 almost 5 years ago
Main changes:
AviatorNil
automatically). For example, it will throw a NullPointerException
on runtime if the custom function returns java's null right now, you should return AviatorNil.Nil
instead. But with this improvement, you can just return the null
in custom functions, aviator will replace the null
with AviatorNil
automatically for you.Published by killme2008 almost 5 years ago
Main changes:
Published by killme2008 almost 5 years ago
Main changes:
Published by killme2008 about 5 years ago
Main changes:
AviatorEvaluator#exec
, please use AviatorEvaluator#execute
instead.FunctionMissing
interface.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).Published by killme2008 about 5 years ago
Main features:
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}
.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.map
and reduce
function now support java.util.Map
, the element type is Map.Entry
, #164Published by killme2008 about 5 years ago
AviatorEvaluator.addStaticFunctions
shoud be static.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')
Published by killme2008 about 5 years ago
Main features:
AviatorEvaluator.addStaticFunctions(namespace, clazz)
and AviatorEvaluatorInstanc#addStaticFunctions(namespace, clazz)
to import class public static methods as custom functions under namespace #155Pattern
instance, it's a string before.Published by killme2008 about 5 years ago
SringContextFunctionLoader.java
-> SpringContextFunctionLoader
Many code style,compile warnings and document errors fixed, thanks to @oldratlee contribution.
Published by killme2008 over 5 years ago
Main features:
Options.ALWAYS_PARSE_INTEGRAL_NUMBER_INTO_DECIMAL
that will parse all integral numbers into big decimal, thanks to @aliiohs #124seq.contains_key(map, key)
to check if the key object is exists in a map and fixed Env#contains_key
#122List<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__")
.
Published by killme2008 over 5 years ago
Main features:
FunctionUtils#getJavaObject
to retrieve java collection type such as (user.roles) #106Options.DISABLE_ASSIGNMENT
to disable variable assignment.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.seq.add
,seq.remove
and seq.get
to add/remove/get elements(values) from collections.seq.max(coll)
and seq.min(coll)
to retrieve min/max element in a sequence.min(x,y,z...)
and max(x,y,z...)
to retrieve min/max value from varidic arguments.identity(x)
function to return the argument itself.Maven
<dependency>
<groupId>com.googlecode.aviator</groupId>
<artifactId>aviator</artifactId>
<version>4.1.2</version>
</dependency>
Published by killme2008 almost 6 years ago
主要改动如下:
AviatorEvaluator.exec(exp, args...)
方法,都推荐使用 execute
方法明确传入 env
map 的方式。此版本推荐升级。
`Maven 依赖:
<dependency>
<groupId>com.googlecode.aviator</groupId>
<artifactId>aviator</artifactId>
<version>4.1.1</version>
</dependency>