aboutsummaryrefslogtreecommitdiff
path: root/bindgen/gen_zig.py
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2025-07-15 18:54:05 +0200
committerAndre Weissflog <floooh@gmail.com>2025-07-15 18:54:05 +0200
commit199dc85b619ad868d01a9ff108372a47de6f96a5 (patch)
tree30d647deafa8e8c4b2a41e88e8b4c250b0ca9430 /bindgen/gen_zig.py
parent7457cae7337d58f09f95294904321a5d5aa14230 (diff)
fix sokol-zig codegen for zig 0.15.0-dev.1034+bd97b6618 (callconv and removed Writer usage)
Diffstat (limited to 'bindgen/gen_zig.py')
-rw-r--r--bindgen/gen_zig.py32
1 files changed, 6 insertions, 26 deletions
diff --git a/bindgen/gen_zig.py b/bindgen/gen_zig.py
index 0281e9b8..e877e6eb 100644
--- a/bindgen/gen_zig.py
+++ b/bindgen/gen_zig.py
@@ -352,7 +352,7 @@ def gen_struct(decl, prefix):
elif is_const_prim_ptr(field_type):
l(f" {field_name}: ?[*]const {as_zig_prim_type(util.extract_ptr_type(field_type))} = null,")
elif util.is_func_ptr(field_type):
- l(f" {field_name}: ?*const fn ({funcptr_args_c(field_type, prefix)}) callconv(.C) {funcptr_result_c(field_type)} = null,")
+ l(f" {field_name}: ?*const fn ({funcptr_args_c(field_type, prefix)}) callconv(.c) {funcptr_result_c(field_type)} = null,")
elif util.is_1d_array_type(field_type):
array_type = util.extract_array_type(field_type)
array_sizes = util.extract_array_sizes(field_type)
@@ -507,33 +507,13 @@ def gen_helpers(inp):
l('}')
l('')
if inp['prefix'] == 'sdtx_':
- l('// std.fmt compatible Writer')
- l('pub const Writer = struct {')
- l(' pub const Error = error{};')
- l(' pub fn writeAll(self: Writer, bytes: []const u8) Error!void {')
- l(' _ = self;')
- l(' for (bytes) |byte| {')
- l(' putc(byte);')
- l(' }')
- l(' }')
- l(' pub fn writeByteNTimes(self: Writer, byte: u8, n: usize) Error!void {')
- l(' _ = self;')
- l(' var i: u64 = 0;')
- l(' while (i < n) : (i += 1) {')
- l(' putc(byte);')
- l(' }')
- l(' }')
- l(' pub fn writeBytesNTimes(self: Writer, bytes: []const u8, n: usize) Error!void {')
- l(' var i: usize = 0;')
- l(' while (i < n) : (i += 1) {')
- l(' try self.writeAll(bytes);')
- l(' }')
- l(' }')
- l('};')
l('// std.fmt-style formatted print')
l('pub fn print(comptime fmt: anytype, args: anytype) void {')
- l(' const writer: Writer = .{};')
- l(' @import("std").fmt.format(writer, fmt, args) catch {};')
+ l(' const cbuf = getClearedFmtBuffer();')
+ l(' const p: [*]u8 = @constCast(@ptrCast(cbuf.ptr));')
+ l(' const buf = p[0..cbuf.size];')
+ l(' const out = @import("std").fmt.bufPrint(buf, fmt, args) catch "";')
+ l(' for (out) |c| putc(c);')
l('}')
l('')