Skip to content

Commit

Permalink
walk it back
Browse files Browse the repository at this point in the history
  • Loading branch information
davydog187 committed Sep 9, 2024
1 parent f42f264 commit cafef75
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions lib/lua.ex
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ defmodule Lua do
`Lua.set!/3` can also be used to expose Elixir functions
iex> lua = Lua.set!(Lua.new!(), [:sum], &Enum.sum/1)
iex> lua = Lua.set!(Lua.new(), [:sum], fn args -> [Enum.sum(args)] end)
iex> {[10], _lua} = Lua.eval!(lua, "return sum(1, 2, 3, 4)")
"""
Expand All @@ -183,13 +183,6 @@ defmodule Lua do
end
end)

value =
if is_function(value) do
wrap_anonymous_function(value)
else
value
end

case :luerl_new.set_table_keys_dec(keys, value, state) do
{:ok, _value, state} ->
wrap(state)
Expand Down Expand Up @@ -504,24 +497,6 @@ defmodule Lua do
|> Lua.API.install(module, scope, opts[:data])
end

defp wrap_anonymous_function(func) when is_function(func, 1) do
fn args ->
case func.(args) do
{ret, %Lua{state: state}} -> {List.wrap(ret), state}
other -> List.wrap(other)
end
end
end

defp wrap_anonymous_function(func) when is_function(func, 2) do
fn args, state ->
case func.(args, state) do
{ret, %Lua{state: state}} -> {List.wrap(ret), state}
other -> List.wrap(other)
end
end
end

defp wrap_variadic_function(module, function_name, with_state?) do
# formatted = Util.format_function(module.scope() ++ [function_name], 0)

Expand Down

0 comments on commit cafef75

Please sign in to comment.