pub trait ExternObject: Send + Sync {
// Required methods
fn type_name(&self) -> &str;
fn get(&self, field: &str) -> Result<RuntimeValue, String>;
fn set(&mut self, field: &str, value: RuntimeValue) -> Result<(), String>;
// Provided methods
fn display(&self) -> String { ... }
fn fields(&self) -> Vec<String> { ... }
fn cast(&self, target: &str) -> Result<RuntimeValue, String> { ... }
}Expand description
A live game object exposed to Urd scripts.
Implement this trait for any host-side type (Godot node, ECS entity handle, asset reference, …) that you want scripts to interact with transparently.
§Contract
get/setshould be cheap — they run inline during expression evaluation. Avoid blocking I/O.- Field names are stringly-typed on purpose — the set of fields can be dynamic (e.g. ECS components added at runtime).
- Returning
Err(message)from any method surfaces as aVmErrorat the script level; the message is shown to the script author.
Required Methods§
Sourcefn type_name(&self) -> &str
fn type_name(&self) -> &str
The type name of this external object (e.g. "Node3D",
"CharacterBody3D").
Used for error messages, debug output, and as the discriminator in
match / pattern contexts if you choose to support that later.
Provided Methods§
Sourcefn display(&self) -> String
fn display(&self) -> String
Human-readable string representation, used when the value appears in
string interpolation ("Hello {player}") or to_string() method
calls.
Sourcefn fields(&self) -> Vec<String>
fn fields(&self) -> Vec<String>
List the names of all readable fields.
Primarily useful for editor auto-complete and introspection from scripts. The default implementation returns an empty list.
Sourcefn cast(&self, target: &str) -> Result<RuntimeValue, String>
fn cast(&self, target: &str) -> Result<RuntimeValue, String>
Try to cast / convert this object into a plain RuntimeValue.
target is the type name the script asked for (e.g. "map",
"str", "int"). Return Err if the cast is not supported.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".