MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / inject_object

Method inject_object

aiscript-vm/src/vm/extra.rs:68–86  ·  view source on GitHub ↗
(&mut self, name: &'static str, fields: HashMap<K, serde_json::Value>)

Source from the content-addressed store, hash-verified

66 }
67
68 pub fn inject_object<K>(&mut self, name: &'static str, fields: HashMap<K, serde_json::Value>)
69 where
70 K: AsRef<str> + Eq,
71 {
72 self.arena.mutate_root(|mc, state| {
73 let ctx = state.get_context();
74 let name = state.intern_static(name);
75 let mut obj = Object::default();
76 for (key, value) in fields {
77 obj.fields.insert(
78 state.intern(key.as_ref().as_bytes()),
79 Value::from_serde_value(ctx, &value),
80 );
81 }
82 state
83 .globals
84 .insert(name, Value::Object(Gc::new(mc, RefLock::new(obj))));
85 });
86 }
87}
88
89#[cfg(test)]

Callers 1

test_inject_instanceFunction · 0.80

Calls 7

ObjectClass · 0.85
mutate_rootMethod · 0.80
get_contextMethod · 0.80
as_bytesMethod · 0.80
intern_staticMethod · 0.45
internMethod · 0.45
as_refMethod · 0.45

Tested by 1

test_inject_instanceFunction · 0.64