Skip to content

Commit 20c6f57

Browse files
committed
Improve calls to predefined functions in the "ExampleModule" class
1 parent 61a15ca commit 20c6f57

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/main/java/me/jddev0/ExampleModule.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@ public DataObject load(List<DataObject> args, final int SCOPE_ID) {
2727

2828
//Calling a predefined function
2929
DataObject funcPrintln = getPredefinedFunctionAsDataObject("println");
30-
31-
List<DataObject> funcPrintlnArgs = new ArrayList<>();
32-
funcPrintlnArgs.add(new DataObject("Hello world! From this module!"));
33-
34-
callFunctionPointer(funcPrintln, funcPrintlnArgs, SCOPE_ID);
30+
callFunctionPointer(funcPrintln, Arrays.asList(
31+
new DataObject("Hello world! From this module!")
32+
), SCOPE_ID);
3533

3634
//Calling a predefined function (Alternate way)
37-
List<DataObject> funcPrintlnArgs2 = new ArrayList<>();
38-
funcPrintlnArgs2.add(new DataObject("Another print statement."));
39-
callPredefinedFunction("println", funcPrintlnArgs2, SCOPE_ID);
35+
callPredefinedFunction("println", Arrays.asList(
36+
new DataObject("Another print statement.")
37+
), SCOPE_ID);
4038

4139
exportFunction("exampleFunction", (argumentList, INNER_SCOPE_ID) -> {
4240
List<DataObject> innerCombinedArgs = LangUtils.combineArgumentsWithoutArgumentSeparators(argumentList);
@@ -83,14 +81,12 @@ public DataObject load(List<DataObject> args, final int SCOPE_ID) {
8381
return new DataObject().setInt(-42);
8482
})));
8583

86-
DataObject linkerInclude = getPredefinedFunctionAsDataObject("include");
87-
88-
List<DataObject> linkerIncludeArgs = new ArrayList<>();
89-
linkerIncludeArgs.add(new DataObject("lib.lang"));
90-
linkerIncludeArgs.add(new DataObject("Argument1 from ExampleModule"));
91-
linkerIncludeArgs = LangUtils.separateArgumentsWithArgumentSeparators(linkerIncludeArgs);
92-
93-
DataObject ret = callFunctionPointer(linkerInclude, linkerIncludeArgs, SCOPE_ID);
84+
DataObject ret = callPredefinedFunction("include", LangUtils.separateArgumentsWithArgumentSeparators(
85+
Arrays.asList(
86+
new DataObject("lib.lang"),
87+
new DataObject("Argument1 from ExampleModule")
88+
)
89+
), SCOPE_ID);
9490

9591
//Accessing exported module variables within the module (The module name must be used [Use lmc.getName()])
9692
Map<String, DataObject> exportedVars = lii.getModuleExportedVariables(lmc.getName());

0 commit comments

Comments
 (0)