Skip to content

Commit 045d7f4

Browse files
committed
Fix array support for native java integration
1 parent f66a072 commit 045d7f4

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ private TypeID loadType(Type type, boolean nullable, boolean unsigned) {
503503
return unsignedByClass.get(classType);
504504
else
505505
throw new IllegalArgumentException("This class cannot be used as unsigned: " + classType);
506+
} else if (classType.isArray()) {
507+
return registry.getArray(loadType(classType.getComponentType(), false, false).stored(), 1);
506508
}
507509

508510
if (typeByClass.containsKey(classType))

ScriptingExample/scripts/integration.zs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ val testInstance = new TestOperators();
1717
//testInstance("something");
1818

1919
something.dump();
20+
21+
val objects = makeArray(5);
22+
printMany(objects);

ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Globals.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,23 @@ private Globals() {}
1717
@Global
1818
public static TestClass something = new TestClass("hello");
1919

20+
@Global
21+
public static TestClass[] makeArray(int amount) {
22+
TestClass[] result = new TestClass[amount];
23+
for (int i = 0; i < result.length; i++)
24+
result[i] = new TestClass("test " + i);
25+
return result;
26+
}
27+
2028
@Global
2129
public static void println(String message) {
2230
System.out.println(message);
2331
}
32+
33+
@Global
34+
public static void printMany(TestClass[] objects) {
35+
System.out.println(objects.length + " objects present:");
36+
for (TestClass object : objects)
37+
System.out.println(" - " + object.getName());
38+
}
2439
}

common.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ apply plugin: 'java'
66
apply plugin: 'maven'
77

88
String mavenGroupId = 'org.openzen.zencode'
9-
String mavenVersion = '0.3.1'
9+
String mavenVersion = '0.3.3'
1010

1111
sourceCompatibility = '1.8'
1212
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

0 commit comments

Comments
 (0)