package lc.mecha.calc;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class CalcEngine {
    private final ScriptEngine scriptEngine;

    public CalcEngine() {
        ScriptEngineManager mgr = new ScriptEngineManager();
        scriptEngine = mgr.getEngineByName("graal.js");
    }

    public String calc(String expr) throws ScriptException {
        Object o = scriptEngine.eval(expr);
        return String.valueOf(o);
    }
}
