Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit3bb1da2647

README.md

component_proxy

Computed-property registry shared by every component proxy. The proxy ITSELF is installed in Rust (crates/zero_scripting/src/world_context.rs::setup_public_dirty_tracking) — this module owns only the cross-VM-instance bookkeeping for public.X = computed(fn) declarations: the global registry table and the sentinel-string protocol that lets dispatch survive any serialization the engine performs on the public table. Installs computed as a _G global via M.installGlobal().

Exports

  • M.computed(fn: (any) -> any) -> string — stash fn keyed by a deterministic sentinel and return the sentinel string. Errors if fn is not a function.
  • M.installGlobal() — install computed as a _G.computed so component modules can write public.X = computed(fn) without an explicit require. Prelude calls this once.

Usage

local CP = require("@builtin::modules.component_proxy")

-- Once, at boot (prelude does this):
CP.installGlobal()

-- In a component module's top-level body:
public.area = computed(function(self) return self.w * self.h end)

Notes

  • The sentinel prefix (__zero_computed__) and registry global name (__zero_computed_registry__) are duplicated in crates/zero_scripting/src/world_context.rs (COMPUTED_SENTINEL_PREFIX). Renaming either side requires the matching rename on the other.
  • The registry is a _G table; it survives module hot-reload but every call to computed(fn) registers a fresh sentinel (sentinel includes tostring(fn)), so re-running a component module replaces its computed entries rather than leaking old ones — provided fn is a fresh closure each time.
  • installGlobal is idempotent. Re-running it just overwrites the global with the same function.