tv-labs / lua

The most ergomonic interface to Luerl in Elixir
https://hexdocs.pm/lua/
Apache License 2.0
71 stars 0 forks source link

Add call_function!/3 #15

Closed davydog187 closed 7 months ago

davydog187 commented 7 months ago

Adds a new API function call_function!/3 which executes Lua functions inside the passed environment. Allows for calling functions by keys (fully qualified name), references, and direct function callbacks

Also adds the encode!/1 function for encoding values

Usage

defmodule MyAPI do
  use Lua.API, scope: "example"

  deflua foo(value), state do
    Lua.call_function!(state, [:string, :lower], [value])
  end
end

lua = Lua.new() |> Lua.load_api(MyAPI)

{["wow"], _} = Lua.eval!(lua, "return example.foo(\"WOW\")")