Search in sources :

Example 6 with AviatorEvaluatorInstance

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()));
}
Also used : AviatorEvaluatorInstance(com.googlecode.aviator.AviatorEvaluatorInstance) Map(java.util.Map)

Example 7 with AviatorEvaluatorInstance

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)); }"));
}
Also used : AviatorEvaluatorInstance(com.googlecode.aviator.AviatorEvaluatorInstance)

Example 8 with AviatorEvaluatorInstance

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);
}
Also used : StringSegments(com.googlecode.aviator.AviatorEvaluatorInstance.StringSegments) AviatorEvaluatorInstance(com.googlecode.aviator.AviatorEvaluatorInstance) BaseExpression(com.googlecode.aviator.BaseExpression)

Aggregations

AviatorEvaluatorInstance (com.googlecode.aviator.AviatorEvaluatorInstance)8 Map (java.util.Map)2 StringSegments (com.googlecode.aviator.AviatorEvaluatorInstance.StringSegments)1 BaseExpression (com.googlecode.aviator.BaseExpression)1 Expression (com.googlecode.aviator.Expression)1 AviatorFunction (com.googlecode.aviator.runtime.type.AviatorFunction)1 AviatorJavaType (com.googlecode.aviator.runtime.type.AviatorJavaType)1 AviatorObject (com.googlecode.aviator.runtime.type.AviatorObject)1 AviatorRuntimeJavaType (com.googlecode.aviator.runtime.type.AviatorRuntimeJavaType)1 AviatorString (com.googlecode.aviator.runtime.type.AviatorString)1 AviatorScriptEngine (com.googlecode.aviator.script.AviatorScriptEngine)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ScriptEngine (javax.script.ScriptEngine)1 ScriptEngineManager (javax.script.ScriptEngineManager)1 Test (org.junit.Test)1