Skip to content

Commit

Permalink
Merge pull request #3 from tv-labs/api-docs
Browse files Browse the repository at this point in the history
Fix the API docs
  • Loading branch information
davydog187 authored Mar 7, 2024
2 parents 2fe55c4 + 97909c2 commit cbd8f27
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/lua/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Lua.API do
use Lua.API
# Can be called via `print("hi")` in lua
def print(msg), do: IO.puts msg
deflua print(msg), do: IO.puts msg
end
Optionally, you can provide a scope
Expand All @@ -17,8 +17,31 @@ defmodule Lua.API do
use Lua.API, scope: "namespace.domain"
# Can be called via `namespace.domain.foo(5)` in lua
def foo(v), do: v
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
"""

defmacro __using__(opts) do
Expand Down

0 comments on commit cbd8f27

Please sign in to comment.