screeps/memory.rs
1//! Interface with Screeps' `Memory` global variable
2//!
3//! If you wish to access the `Memory` object stored in the javascript heap
4//! which has its encoding, storage, and decoding from JSON handled by the game,
5//! this allows accessing a reference to the [`ROOT`] of Memory object. Game
6//! objects which have an automatic memory accessor can access references to
7//! their respective parts of the object, eg.
8//! [`Creep::memory`]/[`StructureSpawn::memory`]. You can work with these
9//! objects using [`js_sys::Reflect`], or by converting the value into a
10//! wasm_bindgen compatible type with the properly access functions you need via
11//! [`wasm_bindgen::JsCast`].
12//!
13//! [`ROOT`]: crate::memory::ROOT
14//! [`Creep::memory`]: crate::objects::Creep::memory
15//! [`StructureSpawn::memory`]: crate::objects::StructureSpawn::memory
16use js_sys::Object;
17use wasm_bindgen::prelude::*;
18
19#[wasm_bindgen]
20extern "C" {
21 /// Get a reference to the `Memory` global object. Note that this object
22 /// gets recreated each tick by the Screeps engine, so references from it
23 /// should not be held beyond the current tick.
24 #[wasm_bindgen(js_name = Memory)]
25 pub static ROOT: Object;
26
27}