feat: add 'a' format specifier and null-value support to wrenCall, plus tests for strings with null bytes

Add a new 'a' format specifier to wrenCall that accepts an explicit byte array and length, enabling callers to pass strings containing null bytes without truncation. Also allow passing NULL for 'v' specifier arguments to produce a Wren NULL value. Rename setForeignCallbacks to setTestCallbacks for clarity. Extend the test suite with a new call.c test file that exercises all argument types including 'a' and 'v' with NULL, and add returnString/returnBytes foreign methods to verify wrenReturnString handles both null-terminated and explicit-length strings correctly.
This commit is contained in:
Bob Nystrom
2015-09-24 15:02:31 +00:00
parent 5e63e65752
commit b19d85f618
11 changed files with 159 additions and 14 deletions
+45
View File
@@ -0,0 +1,45 @@
class Api {
static noParams {
System.print("noParams")
}
static zero() {
System.print("zero")
}
static one(one) {
System.print("one " + one.toString)
}
static two(one, two) {
// Don't print null bytes.
if (two is String && two.bytes.contains(0)) {
two = two.bytes.toList
}
System.print("two " + one.toString + " " + two.toString)
}
static getValue(value) {
// Return a new value if we aren't given one.
if (value == null) return ["a", "b"]
// Otherwise print it.
System.print(value)
}
foreign static runTests()
}
Api.runTests()
// expect: noParams
// expect: zero
// expect: one 1
// expect: two 1 2
// expect: two true false
// expect: two 1.2 3.4
// expect: two 3 4
// expect: two string another
// expect: two null [a, b]
// expect: two str [98, 0, 121, 0, 116, 0, 101]