mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-16 13:00:41 +08:00
feature #I64T29 增加脚本语言Lua的支持
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package com.yomahub.liteflow.script.lua;
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.script.jsr223.JSR223ScriptExecutor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Lua脚本语言的执行器实现
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.9.5
|
||||
*/
|
||||
public class LuaScriptExecutor extends JSR223ScriptExecutor {
|
||||
@Override
|
||||
protected String scriptEngineName() {
|
||||
return "luaj";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String convertScript(String script) {
|
||||
String[] lineArray = script.split("\\n");
|
||||
List<String> noBlankLineList = Arrays.stream(lineArray).filter(
|
||||
s -> !StrUtil.isBlank(s)
|
||||
).collect(Collectors.toList());
|
||||
|
||||
//用第一行的缩进的空格数作为整个代码的缩进量
|
||||
String blankStr = ReUtil.getGroup0("^[ ]*", noBlankLineList.get(0));
|
||||
|
||||
//重新构建脚本
|
||||
StringBuilder scriptSB = new StringBuilder();
|
||||
noBlankLineList.forEach(s
|
||||
-> scriptSB.append(StrUtil.format("{}\n", s.replaceFirst(blankStr, StrUtil.EMPTY))));
|
||||
return scriptSB.toString();
|
||||
//return StrUtil.format("function process()\n{}\nend\nprocess()\n",scriptSB.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# Lua的实现
|
||||
com.yomahub.liteflow.script.lua.LuaScriptExecutor
|
||||
Reference in New Issue
Block a user