aboutsummaryrefslogtreecommitdiff
path: root/bindgen/gen_zig.py
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2025-10-06 14:56:33 +0200
committerAndre Weissflog <floooh@gmail.com>2025-10-06 14:56:33 +0200
commit8f9c6ed69b5f30d7223c91ae498f2c4fe086cfbe (patch)
treee756f9032ea354837ba40d27dcd9e9cee031e150 /bindgen/gen_zig.py
parentae52bb4d84b72bc48dcaf1d57282fad1af7e8c45 (diff)
sokol-zig bindgen: fix asRange() helper for sentinel-terminated arrays (fixes: https://github.com/floooh/sokol-zig/issues/136)
Diffstat (limited to 'bindgen/gen_zig.py')
-rw-r--r--bindgen/gen_zig.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/bindgen/gen_zig.py b/bindgen/gen_zig.py
index e877e6eb..78b42f26 100644
--- a/bindgen/gen_zig.py
+++ b/bindgen/gen_zig.py
@@ -490,10 +490,13 @@ def gen_helpers(inp):
l('pub fn asRange(val: anytype) Range {')
l(' const type_info = @typeInfo(@TypeOf(val));')
l(' switch (type_info) {')
- l(' .pointer => {')
- l(' switch (type_info.pointer.size) {')
- l(' .one => return .{ .ptr = val, .size = @sizeOf(type_info.pointer.child) },')
- l(' .slice => return .{ .ptr = val.ptr, .size = @sizeOf(type_info.pointer.child) * val.len },')
+ l(' .pointer => |pointer| {')
+ l(' switch (pointer.size) {')
+ l(' .one => switch (@typeInfo(pointer.child)) {')
+ l(' .array => |array| return .{ .ptr = val, .size = array.len * @sizeOf(array.child) },')
+ l(' else => return .{ .ptr = val, .size = @sizeOf(pointer.child) },')
+ l(' },')
+ l(' .slice => return .{ .ptr = val.ptr, .size = val.len * @sizeOf(pointer.child) },')
l(' else => @compileError("FIXME: Pointer type!"),')
l(' }')
l(' },')
@@ -501,7 +504,7 @@ def gen_helpers(inp):
l(' @compileError("Structs and arrays must be passed as pointers to asRange");')
l(' },')
l(' else => {')
- l(' @compileError("Cannot convert to range!");')
+ l(' @compileError("Cannot convert to Range!");')
l(' },')
l(' }')
l('}')