Skip to main content

ScriptContext

Trait ScriptContext 

Source
pub trait ScriptContext {
    // Required methods
    fn get(&self, name: &str) -> Option<ScriptValue>;
    fn set(&mut self, name: &str, value: ScriptValue);
    fn array_push(&mut self, name: &str, value: ScriptValue);
    fn array_clear(&mut self, name: &str);

    // Provided method
    fn entity(&self, entity_id: &str, name: &str) -> Option<ScriptValue> { ... }
}
Expand description

Backend-agnostic facade exposing the reactive property store to script hosts. Mirrors QML’s QQmlContext::setContextProperty / contextProperty() shape: scripts read + write through a thin layer the host keeps internally so callers don’t have to thread an Engine or a per-backend Dynamic type through.

Concrete impls own the underlying signal store. The trait is intentionally small: every method maps to one host-side write so backends can rebuild their internal mirror without re-implementing scalar/array policy on top of Dynamic.

Required Methods§

Source

fn get(&self, name: &str) -> Option<ScriptValue>

Read a named scalar / structured property. None => the property has never been written.

Source

fn set(&mut self, name: &str, value: ScriptValue)

Write a named scalar / structured property. The backend mirrors the write into its native value type and queues a stringified SetSignal for the ECS-side Signals resource.

Source

fn array_push(&mut self, name: &str, value: ScriptValue)

Append value onto the named array property. Lazy-initialises the array if absent. Drives <for each="<name>"> reconciliation.

Source

fn array_clear(&mut self, name: &str)

Clear the named array property (set to empty).

Provided Methods§

Source

fn entity(&self, entity_id: &str, name: &str) -> Option<ScriptValue>

Entity-scoped read for properties keyed by (entity_id, name). Returns None when the backend doesn’t model entity-scoped properties (most backends do not).

Implementors§