mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
feature #I64T29 增加脚本语言Lua的支持
This commit is contained in:
28
liteflow-script-plugin/liteflow-script-lua/pom.xml
Normal file
28
liteflow-script-plugin/liteflow-script-lua/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>liteflow-script-plugin</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>liteflow-script-lua</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-core</artifactId>
|
||||
<version>${revision}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.luaj</groupId>
|
||||
<artifactId>luaj-jse</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -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
|
||||
@@ -4,9 +4,10 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-plugin</artifactId>
|
||||
<version>2.9.5</version>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>liteflow-script-python</artifactId>
|
||||
|
||||
@@ -29,7 +29,7 @@ public class PythonScriptExecutor extends JSR223ScriptExecutor {
|
||||
//用第一行的缩进的空格数作为整个代码的缩进量
|
||||
String blankStr = ReUtil.getGroup0("^[ ]*", noBlankLineList.get(0));
|
||||
|
||||
//重新构建python脚本
|
||||
//重新构建脚本
|
||||
StringBuilder scriptSB = new StringBuilder();
|
||||
noBlankLineList.forEach(s
|
||||
-> scriptSB.append(StrUtil.format("{}\n", s.replaceFirst(blankStr, StrUtil.EMPTY))));
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<module>liteflow-script-javascript</module>
|
||||
<module>liteflow-script-graaljs</module>
|
||||
<module>liteflow-script-python</module>
|
||||
<module>liteflow-script-lua</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user