瀏覽代碼

Created ScriptingEngine#createScriptedModule overload that accepts loggers

kindlich 5 年之前
父節點
當前提交
2255428bd9
沒有發現已知的金鑰在資料庫的簽署中
共有 1 個文件被更改,包括 17 次插入2 次删除
  1. 17
    2
      JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java

+ 17
- 2
JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java 查看文件

@@ -11,6 +11,8 @@ import java.util.ArrayList;
11 11
 import java.util.Collections;
12 12
 import java.util.List;
13 13
 import java.util.Map;
14
+import java.util.function.Consumer;
15
+
14 16
 import org.openzen.zencode.shared.CompileException;
15 17
 import org.openzen.zencode.shared.SourceFile;
16 18
 import org.openzen.zenscript.codemodel.FunctionParameter;
@@ -29,6 +31,7 @@ import org.openzen.zenscript.lexer.ParseException;
29 31
 import org.openzen.zenscript.parser.BracketExpressionParser;
30 32
 import org.openzen.zenscript.parser.ParsedFile;
31 33
 import org.openzen.zenscript.parser.ZippedPackage;
34
+import org.openzen.zenscript.validator.ValidationLogEntry;
32 35
 import org.openzen.zenscript.validator.Validator;
33 36
 
34 37
 /**
@@ -92,6 +95,18 @@ public class ScriptingEngine {
92 95
 			BracketExpressionParser bracketParser,
93 96
 			FunctionParameter[] scriptParameters,
94 97
 			String... dependencies) throws ParseException
98
+	{
99
+		return createScriptedModule(name, sources, bracketParser, scriptParameters, Throwable::printStackTrace, System.out::println , dependencies);
100
+	}
101
+	
102
+	public SemanticModule createScriptedModule(
103
+			String name,
104
+			SourceFile[] sources,
105
+			BracketExpressionParser bracketParser,
106
+			FunctionParameter[] scriptParameters,
107
+			Consumer<CompileException> compileExceptionConsumer,
108
+			Consumer<ValidationLogEntry> validatorErrorConsumer,
109
+			String... dependencies) throws ParseException
95 110
 	{
96 111
 		Module scriptModule = new Module(name);
97 112
 		CompilingPackage scriptPackage = new CompilingPackage(new ZSPackage(space.rootPackage, name), scriptModule);
@@ -112,13 +127,13 @@ public class ScriptingEngine {
112 127
 				files,
113 128
 				space,
114 129
 				scriptParameters,
115
-				ex -> ex.printStackTrace());
130
+				compileExceptionConsumer);
116 131
 		if (!scripts.isValid())
117 132
 			return scripts;
118 133
 		
119 134
 		return Validator.validate(
120 135
 				scripts.normalize(),
121
-				error -> System.out.println(error.toString()));
136
+				validatorErrorConsumer);
122 137
 	}
123 138
 	
124 139
 	public void registerCompiled(SemanticModule module) {

Loading…
取消
儲存