Rhai.Scope (rhai_rustler v1.0.2)

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

@type t() :: %Rhai.Scope{reference: term(), resource: term()}

Functions

@spec clear(t()) :: t()

Empty the Scope.

Link to this function

clone_visible(scope)

@spec clone_visible(t()) :: t()

Clone the Scope, keeping only the last instances of each variable name. Shadowed variables are omitted in the copy.

Link to this function

constant?(scope, name)

@spec constant?(t(), String.t()) :: nil | bool()

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.

Link to this function

contains?(scope, name)

@spec contains?(t(), String.t()) :: bool()

Does the Scope contain the entry?

@spec empty?(t()) :: bool()

Returns true if this Scope contains no variables.

Link to this function

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.

@spec len(t()) :: non_neg_integer()

Get the number of entries inside the Scope.

@spec new() :: t()

Create a new Scope

@spec pop(t()) :: {:ok, t()} | {:error, {:scope_is_empty, String.t()}}

Remove the last entry from the Scope.

Returns an error if the Scope is empty.

@spec pop!(t()) :: t()

Remove the last entry from the Scope.

Raises if the Scope is empty.

Link to this function

push(scope, name, value)

@spec push(t(), String.t(), Rhai.Any.t()) :: t()

Add (push) a new entry to the Scope.

Link to this function

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.

Link to this function

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.

Link to this function

rewind(scope, size)

@spec rewind(t(), non_neg_integer()) :: t()

Truncate (rewind) the Scope to a previous size.

Link to this function

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.

Link to this function

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.

Link to this function

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.

Link to this function

with_capacity(capacity)

@spec with_capacity(non_neg_integer()) :: t()

Create a new Scope with a particular capacity.