Skip to content

Commit

Permalink
Alias fully qualified names in demo
Browse files Browse the repository at this point in the history
  • Loading branch information
pyotrk committed May 25, 2026
1 parent c1d7fc7 commit 2e352ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions crdt-demo/runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! CRDT server binary, then waits for the server to exit.

const std = @import("std");
const spawn = spawn;

pub fn main(init: std.process.Init) !void {
const io = init.io;
Expand All @@ -14,15 +15,15 @@ pub fn main(init: std.process.Init) !void {
const www_dir = args.next() orelse return error.MissingArg;
const server_bin = args.next() orelse return error.MissingArg;

var python_child = try std.process.spawn(io, .{
var python_child = try spawn(io, .{
.argv = &.{ python, "-m", "http.server", "-d", www_dir },
.stdin = .ignore,
.stdout = .inherit,
.stderr = .inherit,
});
errdefer python_child.kill(io);

var server_child = try std.process.spawn(io, .{
var server_child = try spawn(io, .{
.argv = &.{ server_bin },
.stdin = .ignore,
.stdout = .ignore,
Expand Down
6 changes: 4 additions & 2 deletions crdt-demo/src/demo.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//! counter. JS glue in www/demo.js drives a contenteditable editor.
const std = @import("std");
const crdt = @import("crdt");
const Stringify = std.json.Stringify;
const parseFromSlice = std.json.parseFromSlice;

const ReplicaId = crdt.ReplicaId;
const Rga = crdt.Rga(u8);
Expand Down Expand Up @@ -125,7 +127,7 @@ export fn get_state_json(handle_ptr: usize) void {
const crdt_val = Crdt{ .rga = handle.rga };
var buf: std.Io.Writer.Allocating = .init(allocator);
defer buf.deinit();
std.json.Stringify.value(crdt_val, .{}, &buf.writer) catch {
Stringify.value(crdt_val, .{}, &buf.writer) catch {
output.clearRetainingCapacity();
return;
};
Expand All @@ -146,7 +148,7 @@ export fn get_state_json(handle_ptr: usize) void {
export fn merge_json(handle_ptr: usize, json_ptr: [*]const u8, json_len: usize) void {
const handle = handle_map.get(handle_ptr) orelse return;
const json_slice = json_ptr[0..json_len];
const parsed = std.json.parseFromSlice(Crdt, allocator, json_slice, .{}) catch return;
const parsed = parseFromSlice(Crdt, allocator, json_slice, .{}) catch return;
defer parsed.deinit();
handle.rga.merge(parsed.value.rga, allocator) catch {};
}
Expand Down

0 comments on commit 2e352ec

Please sign in to comment.