package net.northking.cctp.dataPool.utils;

import bsh.EvalError;
import bsh.Interpreter;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class ScriptUtil {


    //传进脚本内容，返回执行结果
    public static Object executeBeanShell(String scriptContent) throws EvalError {
        Interpreter interpreter = new Interpreter();
        Object o = interpreter.eval(scriptContent);
        return o;
    }

    public static List executesBeanShell(String scriptContent,Integer execNum) throws EvalError {
        List values  = new ArrayList();
        for (Integer i = 0; i < execNum; i++) {
            values.add(executeBeanShell(scriptContent));

        }
        return values;
    }

}
