Skip to content

Commit 462d14a

Browse files
committed
fix(examples): support Zig 0.14 in web_app_multi_client
- use allocPrintZ for JS string formatting when Zig 0.14 is detected - maintain compatibility with previous Zig versions using allocPrintSentinel
1 parent d133ffc commit 462d14a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/web_app_multi_client/main.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const std = @import("std");
22
const webui = @import("webui");
3+
const builtin = @import("builtin");
34

45
// general purpose allocator
56
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
@@ -40,7 +41,11 @@ fn saveAll(e: *webui.Event) void {
4041
public_input = allocator.dupe(u8, publicInput) catch unreachable;
4142

4243
// general new js
43-
const js = std.fmt.allocPrintSentinel(
44+
const js = if (builtin.zig_version.minor == 14) std.fmt.allocPrintZ(
45+
allocator,
46+
"document.getElementById(\"publicInput\").value = \"{s}\";",
47+
.{publicInput},
48+
) catch unreachable else std.fmt.allocPrintSentinel(
4449
allocator,
4550
"document.getElementById(\"publicInput\").value = \"{s}\";",
4651
.{publicInput},

0 commit comments

Comments
 (0)