Operate v0.1.0-beta.15 Operate.Cell View Source

Module for working with Operate tape cells.

A cell represents a single atomic procedure call. A Operate.Cell.t/0 contains the Op script and parameters. When the cell is executed it returns a result.

Examples

iex> %Operate.Cell{op: "return function(state, a, b) return state + a + b end", params: [3, 5]}
...> |> Operate.Cell.exec(Operate.VM.init, state: 1)
{:ok, 9}

Link to this section Summary

Types

t()

Operate Cell

Functions

Executes the given cell in the given VM state.

As exec/3, but returns the result or raises an exception.

Converts the given Operate.BPU.Cell.t/0 into a Operate.Cell.t/0. Returns the result in an :ok / :error tuple pair.

As from_bpu/1, but returns the result or raises an exception.

Validates the given cell. Returns true if the cell has a reference and script.

Link to this section Types

Specs

t() :: %Operate.Cell{
  data_index: integer(),
  index: integer(),
  op: String.t(),
  params: list(),
  ref: String.t()
}

Operate Cell

Link to this section Functions

Link to this function

exec(cell, vm, options \\ [])

View Source

Specs

exec(t(), Operate.VM.t(), keyword()) ::
  {:ok, Operate.VM.lua_output()} | {:error, String.t()}

Executes the given cell in the given VM state.

Options

The accepted options are:

  • :state - Specifiy the state which is always the first parameter in the executed function. Defaults to nil.

Examples

iex> %Operate.Cell{op: "return function(state) return state..' world' end", params: []}
...> |> Operate.Cell.exec(Operate.VM.init, state: "hello")
{:ok, "hello world"}
Link to this function

exec!(cell, vm, options \\ [])

View Source

Specs

As exec/3, but returns the result or raises an exception.

Options

The accepted options are:

  • :state - Specifiy the state which is always the first parameter in the executed function. Defaults to nil.

Specs

from_bpu(Operate.BPU.Cell.t()) :: {:ok, t()} | {:error, String.t()}

Converts the given Operate.BPU.Cell.t/0 into a Operate.Cell.t/0. Returns the result in an :ok / :error tuple pair.

Specs

from_bpu!(Operate.BPU.Cell.t()) :: t()

As from_bpu/1, but returns the result or raises an exception.

Specs

valid?(t()) :: boolean()

Validates the given cell. Returns true if the cell has a reference and script.

Examples

iex> %Operate.Cell{ref: "abc", op: "return 123"}
...> |> Operate.Cell.valid?
true

iex> %Operate.Cell{}
...> |> Operate.Cell.valid?
false