use of com.googlecode.aviator.AviatorEvaluatorInstance in project aviatorscript by killme2008.
the class EvalFunction method call.
@SuppressWarnings("unchecked")
@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2) {
AviatorEvaluatorInstance instance = RuntimeUtils.getInstance(env);
String script = FunctionUtils.getStringValue(arg1, env);
return AviatorRuntimeJavaType.valueOf(instance.execute(script, (Map<String, Object>) arg2.getValue(env), instance.isCachedExpressionByDefault()));
}
use of com.googlecode.aviator.AviatorEvaluatorInstance in project aviatorscript by killme2008.
the class ConfigureInstanceExample method main.
public static void main(final String[] args) {
AviatorEvaluatorInstance instance = AviatorEvaluator.newInstance();
instance.setOption(Options.USE_USER_ENV_AS_TOP_ENV_DIRECTLY, false);
instance.setOption(Options.FEATURE_SET, Feature.asSet(Feature.Assignment, Feature.ForLoop, Feature.WhileLoop, Feature.Lambda, Feature.Let));
System.out.println(instance.execute("let square = lambda(x) -> x*2 end; for x in range(0, 10) { p(square(x)); }"));
}
use of com.googlecode.aviator.AviatorEvaluatorInstance in project aviatorscript by killme2008.
the class AviatorString method getLexeme.
public String getLexeme(final Map<String, Object> env, final boolean warnOnCompile) {
AviatorEvaluatorInstance engine = RuntimeUtils.getInstance(env);
if (!this.isLiteral || !this.hasInterpolation || !engine.isFeatureEnabled(Feature.StringInterpolation) || this.lexeme == null || this.lexeme.length() < 3) {
return this.lexeme;
}
StringSegments segs = null;
BaseExpression exp = (BaseExpression) (env == null ? null : env.get(Constants.EXP_VAR));
if (exp != null) {
segs = exp.getStringSegements(this.lexeme, this.lineNo);
} else {
segs = engine.compileStringSegments(this.lexeme);
if (warnOnCompile) {
warnOnCompileWithoutCaching();
}
}
assert (segs != null);
return segs.toString(env, this.lexeme);
}
Aggregations