From 4919c9c2fc84ea2aeb906961028dce516574936c Mon Sep 17 00:00:00 2001 From: Orkuncakilkaya Date: Fri, 25 Sep 2026 14:43:23 +0300 Subject: [PATCH] examples: net_sync's raw buffer inside unsafe, now that a query's body is checked Co-Authored-By: Claude Opus 5.5 --- examples/networking/net_sync.ludic | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/examples/networking/net_sync.ludic b/examples/networking/net_sync.ludic index 58b3e4e5..c6b059b3 100644 --- a/examples/networking/net_sync.ludic +++ b/examples/networking/net_sync.ludic @@ -21,20 +21,22 @@ program NetSync { entry { spawn Player { Position { x: 3, y: 4 }, Health { hp: 50, max: 100 } } - for (Position, Health) in query [Position, Health, {Player}] { - let e = self() - let buf = bytes(64) - print(sync_size(e)) # 12 = Position(x,y)=8 + Health.hp=4 - let n = serialize(e, buf) # snapshot the synced fields - Position.x = 99 # mutate everything - Position.y = 88 - Health.hp = 7 - Health.max = 999 # max is NOT synced - apply(e, buf, n) # restore from the snapshot - print(Position.x) # 3 — restored - print(Position.y) # 4 — restored - print(Health.hp) # 50 — restored - print(Health.max) # 999 — kept (unsynced) + unsafe { # a raw snapshot buffer on purpose: built with --unsafe (L7) + for (Position, Health) in query [Position, Health, {Player}] { + let e = self() + let buf = bytes(64) + print(sync_size(e)) # 12 = Position(x,y)=8 + Health.hp=4 + let n = serialize(e, buf) # snapshot the synced fields + Position.x = 99 # mutate everything + Position.y = 88 + Health.hp = 7 + Health.max = 999 # max is NOT synced + apply(e, buf, n) # restore from the snapshot + print(Position.x) # 3 — restored + print(Position.y) # 4 — restored + print(Health.hp) # 50 — restored + print(Health.max) # 999 — kept (unsynced) + } } } }