pub enum Scope {
Global {
source: BTreeMap<ArcStr, Value>,
extras: ScopeExtras,
},
Local {
overlay: BTreeMap<ArcStr, Value>,
source: *mut Scope,
},
}
Expand description
A Scope
is responsible for keeping track of script state.
This includes storing variables, which are plain Values
.
Function and Objects values are simple indexes|references to FunctionDefinitions
and BTreeMaps
, stored in ScopeExtras
.
ScopeExtras
is only attached to the Global Scope, meaning Functions and Objects are always global, even if defined in a script function.
The default
scope comes with several constants built-in:
{
"Boolean": "__TYPE__BOOLEAN",
"Function": "__TYPE__FUNCTION",
"Nil": "__CONSTANT__NIL",
"Number": "__TYPE__NUMBER",
"Object": "__TYPE__OBJECT",
"String": "__TYPE__STRING",
"PI": 3.1415927,
"E": 2.7182817,
"TAU": 6.2831855,
"false": false,
"true": true
}
Variants§
Implementations§
source§impl Scope
impl Scope
pub fn get_function_definition( &self, idx: usize ) -> EggResult<&FunctionDefinition>
pub fn get_function_definition_mut( &mut self, idx: usize ) -> EggResult<&mut FunctionDefinition>
pub fn call_function( &mut self, idx: usize, parameters: &[Expression], operators: &BTreeMap<&str, Box<dyn Operator>> ) -> EggResult<Value>
pub fn delete_function(&mut self, idx: usize) -> Option<FunctionDefinition>
source§impl Scope
impl Scope
pub fn create_object(&mut self) -> EggResult<Value>
pub fn get_object_tag(&self, tag: Value) -> EggResult<usize>
pub fn get_object(&self, tag: usize) -> &BTreeMap<Value, Value>
pub fn get_object_mut(&mut self, tag: usize) -> &mut BTreeMap<Value, Value>
pub fn delete_object(&mut self, tag: usize) -> Option<BTreeMap<Value, Value>>
source§impl Scope
impl Scope
sourcepub fn exists(&self, key: &str) -> bool
pub fn exists(&self, key: &str) -> bool
Check if a variable exists anywhere in the scope chain.
sourcepub fn exists_locally(&self, key: &str) -> bool
pub fn exists_locally(&self, key: &str) -> bool
Check if a variable exists in the current scope. Has similar behaviour to exists
for the Global Scope.
Used to check if a variable is defined in the current scope, and not in the parent scope.
sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
Fetch for a variable in the current scope and its parent scopes.
sourcepub fn get_mut(&mut self, key: &str) -> Option<&mut Value>
pub fn get_mut(&mut self, key: &str) -> Option<&mut Value>
Mutable fetch for a variable in the current scope and its parent scopes.
sourcepub fn insert(&mut self, key: ArcStr, value: Value) -> EggResult<()>
pub fn insert(&mut self, key: ArcStr, value: Value) -> EggResult<()>
Insert a new variable into the current scope.