Enum egglang::scope::Scope

source ·
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§

§

Global

Fields

§extras: ScopeExtras
§

Local

Fields

§source: *mut Scope

Implementations§

source§

impl Scope

source

pub fn get_function_definition( &self, idx: usize ) -> EggResult<&FunctionDefinition>

source

pub fn get_function_definition_mut( &mut self, idx: usize ) -> EggResult<&mut FunctionDefinition>

source

pub fn call_function( &mut self, idx: usize, parameters: &[Expression], operators: &BTreeMap<&str, Box<dyn Operator>> ) -> EggResult<Value>

source

pub fn delete_function(&mut self, idx: usize) -> Option<FunctionDefinition>

source§

impl Scope

source

pub fn create_object(&mut self) -> EggResult<Value>

source

pub fn get_object_tag(&self, tag: Value) -> EggResult<usize>

source

pub fn get_object(&self, tag: usize) -> &BTreeMap<Value, Value>

source

pub fn get_object_mut(&mut self, tag: usize) -> &mut BTreeMap<Value, Value>

source

pub fn delete_object(&mut self, tag: usize) -> Option<BTreeMap<Value, Value>>

source§

impl Scope

source

pub fn exists(&self, key: &str) -> bool

Check if a variable exists anywhere in the scope chain.

source

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.

source

pub fn get(&self, key: &str) -> Option<&Value>

Fetch for a variable in the current scope and its parent scopes.

source

pub fn get_mut(&mut self, key: &str) -> Option<&mut Value>

Mutable fetch for a variable in the current scope and its parent scopes.

source

pub fn insert(&mut self, key: ArcStr, value: Value) -> EggResult<()>

Insert a new variable into the current scope.

source

pub fn update(&mut self, key: ArcStr, value: Value)

Updates the value of a variable if it is in the present scope, otherwise updates it in the parent scope.

source

pub fn delete(&mut self, key: &str) -> Option<Value>

Delete a variable if it is the present scope, otherwise delete it from the parent scope.

Trait Implementations§

source§

impl Debug for Scope

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Scope

source§

fn default() -> Scope

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Scope

§

impl RefUnwindSafe for Scope

§

impl !Send for Scope

§

impl !Sync for Scope

§

impl Unpin for Scope

§

impl UnwindSafe for Scope

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.