Rhai.Scope (rhai_rustler v1.1.1)
Type containing information about the current scope. Useful for keeping state between Engine evaluation runs. Scope implements the https://hexdocs.pm/elixir/1.12/Enumerable.html protocol.
Summary
Functions
Empty the Scope.
Clone the Scope, keeping only the last instances of each variable name. Shadowed variables are omitted in the copy.
Check if the named entry in the Scope is constant. Search starts backwards from the last, stopping at the first entry matching the specified name. Returns nil if no entry matching the specified name is found.
Does the Scope contain the entry?
Returns true if this Scope contains no variables.
Get the value of an entry in the Scope, starting from the last.
Get the number of entries inside the Scope.
Create a new Scope
Remove the last entry from the Scope.
Remove the last entry from the Scope.
Add (push) a new entry to the Scope.
Add (push) a new constant to the Scope.
Remove the last entry in the Scope by the specified name and return its value.
Truncate (rewind) the Scope to a previous size.
Update the value of the named entry in the Scope if it already exists and is not constant. Push a new entry with the value into the Scope if the name doesn’t exist or if the existing entry is constant.
Update the value of the named entry in the Scope.
Update the value of the named entry in the Scope.
Create a new Scope with a particular capacity.
Types
Functions
clear(scope)
Empty the Scope.
clone_visible(scope)
Clone the Scope, keeping only the last instances of each variable name. Shadowed variables are omitted in the copy.
constant?(scope, name)
Check if the named entry in the Scope is constant. Search starts backwards from the last, stopping at the first entry matching the specified name. Returns nil if no entry matching the specified name is found.
contains?(scope, name)
Does the Scope contain the entry?
empty?(scope)
@spec empty?(t()) :: bool()
Returns true if this Scope contains no variables.
get_value(scope, name)
@spec get_value(t(), String.t()) :: nil | Rhai.Any.t()
Get the value of an entry in the Scope, starting from the last.
len(scope)
@spec len(t()) :: non_neg_integer()
Get the number of entries inside the Scope.
new()
@spec new() :: t()
Create a new Scope
pop(scope)
Remove the last entry from the Scope.
Returns an error if the Scope is empty.
pop!(scope)
Remove the last entry from the Scope.
Raises if the Scope is empty.
push(scope, name, value)
@spec push(t(), String.t(), Rhai.Any.t()) :: t()
Add (push) a new entry to the Scope.
push_constant(scope, name, value)
@spec push_constant(t(), String.t(), Rhai.Any.t()) :: t()
Add (push) a new constant to the Scope.
Constants are immutable and cannot be assigned to. Their values never change. Constants propagation is a technique used to optimize an AST.
remove(scope, name)
@spec remove(t(), String.t()) :: nil | Rhai.Any.t()
Remove the last entry in the Scope by the specified name and return its value.
If the entry by the specified name is not found, None is returned.
rewind(scope, size)
@spec rewind(t(), non_neg_integer()) :: t()
Truncate (rewind) the Scope to a previous size.
set_or_push(scope, name, value)
@spec set_or_push(t(), String.t(), Rhai.Any.t()) :: t()
Update the value of the named entry in the Scope if it already exists and is not constant. Push a new entry with the value into the Scope if the name doesn’t exist or if the existing entry is constant.
Search starts backwards from the last, and only the first entry matching the specified name is updated.
set_value(scope, name, value)
@spec set_value(t(), String.t(), Rhai.Any.t()) :: {:ok, t()} | {:error, {:cannot_update_value_of_constant, String.t()}}
Update the value of the named entry in the Scope.
Search starts backwards from the last, and only the first entry matching the specified name is updated. If no entry matching the specified name is found, a new one is added.
Returns an error when trying to update the value of a constant.
set_value!(scope, name, value)
@spec set_value!(t(), String.t(), Rhai.Any.t()) :: t()
Update the value of the named entry in the Scope.
Search starts backwards from the last, and only the first entry matching the specified name is updated. If no entry matching the specified name is found, a new one is added.
Raises when trying to update the value of a constant.
with_capacity(capacity)
@spec with_capacity(non_neg_integer()) :: t()
Create a new Scope with a particular capacity.