View Source Lua.API behaviour (Lua v0.0.7)

Defines the Behaviour for defining a Lua API

To create a module that exports functions to the global scope

defmodule MyAPI do
  use Lua.API

  # Can be called via `print("hi")` in lua
  deflua print(msg), do: IO.puts msg
end

Optionally, you can provide a scope

defmodule SpecificAPI do
  use Lua.API, scope: "namespace.domain"

  # Can be called via `namespace.domain.foo(5)` in lua
  deflua foo(v), do: v
end

You can access Lua state

defmodule State do
  use Lua.API

  deflua bar(name), state do
    # Pull's the value of `number` out of state
    val = Lua.get!(state, [:number])

    2 * val
  end
end

Regular functions are not exported

defmodule SpecificAPI do
  use Lua.API

  # Won't be exposed
  def baz(v), do: v
end

Summary

Functions

Define a function that can be exposed in Lua

Raises a runtime exception inside an API function, displaying contextual information about where the exception was raised.

Callbacks

@callback scope() :: [String.t()]

Functions

Link to this macro

deflua(fa, list)

View Source (macro)
Link to this macro

deflua(fa, state, list)

View Source (macro)

Define a function that can be exposed in Lua

Link to this macro

runtime_exception!(message)

View Source (macro)

Raises a runtime exception inside an API function, displaying contextual information about where the exception was raised.