Operate v0.1.0-beta.15 Operate.VM.Extension behaviour View Source

Operate VM extension specification.

The Operate Lua VM can be easily extended, either with native Lua modules, or Elixir code that is added to the Lua VM as functions.

Examples

defmodule MyExtension do
  use Operate.VM.Extension
  alias Operate.VMr

  def extend(vm) do
    vm
    |> VM.set!("msg", "hello world")
    |> VM.exec!("function hello() return msg end")
    |> VM.set_function!("sum", fn _vm, args -> apply(__MODULE__, :sum, args) end)
  end

  def sum(a,b) do
    a + b
  end
end

Link to this section Summary

Callbacks

Extends the given VM state, returning the modified state.

Link to this section Callbacks

Specs

extend(Operate.VM.t()) :: Operate.VM.t()

Extends the given VM state, returning the modified state.