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…
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— stashfnkeyed by a deterministic sentinel and return the sentinel string. Errors iffnis not a function.M.installGlobal()— installcomputedas a_G.computedso component modules can writepublic.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 incrates/zero_scripting/src/world_context.rs(COMPUTED_SENTINEL_PREFIX). Renaming either side requires the matching rename on the other. - The registry is a
_Gtable; it survives module hot-reload but every call tocomputed(fn)registers a fresh sentinel (sentinel includestostring(fn)), so re-running a component module replaces its computed entries rather than leaking old ones — providedfnis a fresh closure each time. installGlobalis idempotent. Re-running it just overwrites the global with the same function.
Scoped to this part · feeds back into the world's score.