diff options
| author | Andre Weissflog <floooh@gmail.com> | 2024-08-31 13:10:42 +0200 |
|---|---|---|
| committer | Andre Weissflog <floooh@gmail.com> | 2024-08-31 13:10:42 +0200 |
| commit | faf759354e2bd71a73738b7c54e95786aa17d5e5 (patch) | |
| tree | 09337f6a37d50684d8f422efa6c417e7ab82e425 /bindgen/gen_zig.py | |
| parent | e85b58aaf2e1c7603a0bd0eea7e99a250948299b (diff) | |
sokol-zig: work around a breaking naming convention change in the Zig stdlib
Diffstat (limited to 'bindgen/gen_zig.py')
| -rw-r--r-- | bindgen/gen_zig.py | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/bindgen/gen_zig.py b/bindgen/gen_zig.py index 4b63eebe..7b537586 100644 --- a/bindgen/gen_zig.py +++ b/bindgen/gen_zig.py @@ -466,20 +466,39 @@ def gen_helpers(inp): l('// helper function to convert "anything" to a Range struct') 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(' else => @compileError("FIXME: Pointer type!"),') - l(' }') - l(' },') - l(' .Struct, .Array => {') - l(' @compileError("Structs and arrays must be passed as pointers to asRange");') - l(' },') - l(' else => {') - l(' @compileError("Cannot convert to range!");') - l(' },') + l(' // FIXME: naming convention change between 0.13 and 0.14-dev') + l(' if (@hasField(@TypeOf(type_info), "Pointer")) {') + 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(' else => @compileError("FIXME: Pointer type!"),') + l(' }') + l(' },') + l(' .Struct, .Array => {') + l(' @compileError("Structs and arrays must be passed as pointers to asRange");') + l(' },') + l(' else => {') + l(' @compileError("Cannot convert to range!");') + l(' },') + l(' }') + l(' } else {') + 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(' else => @compileError("FIXME: Pointer type!"),') + l(' }') + l(' },') + l(' .@"struct", .array => {') + l(' @compileError("Structs and arrays must be passed as pointers to asRange");') + l(' },') + l(' else => {') + l(' @compileError("Cannot convert to range!");') + l(' },') + l(' }') l(' }') l('}') l('') |