Lua.VM.Stdlib.Library behaviour (Lua v1.0.0-rc.1)

View Source

Behaviour for Lua standard library modules.

All standard library modules (string, math, table, os, etc.) should implement this behaviour to provide a consistent interface for installation into the VM state.

Example

defmodule Lua.VM.Stdlib.String do
  @behaviour Lua.VM.Stdlib.Library

  @impl true
  def install(state) do
    # Create and register the string library
    string_table = %{...}
    {tref, state} = State.alloc_table(state, string_table)
    State.set_global(state, "string", tref)
  end
end

Summary

Callbacks

Installs the library into the given VM state.

Returns the Lua global name for this library (e.g., "string", "math").

Callbacks

install(t)

@callback install(Lua.VM.State.t()) :: Lua.VM.State.t()

Installs the library into the given VM state.

This function should register all library functions in the appropriate global namespace (e.g., "string", "math", "table") and return the updated state.

Parameters

  • state - The VM state to install the library into

Returns

The updated VM state with the library installed

lib_name()

@callback lib_name() :: String.t()

Returns the Lua global name for this library (e.g., "string", "math").

Used to register the library in package.loaded so that require("string") etc. works.