Skip to content

Commit

Permalink
start using new luerl encode/decode
Browse files Browse the repository at this point in the history
  • Loading branch information
davydog187 committed Dec 17, 2024
1 parent 4787c7c commit 2e406de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions lib/lua.ex
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ defmodule Lua do
Enum.reduce_while(keys, {[], state}, fn key, {keys, state} ->
keys = keys ++ [key]

case :luerl_new.get_table_keys_dec(keys, state) do
case :luerl.get_table_keys_dec(keys, state) do
{:ok, nil, state} ->
{:cont, set_keys!(state, keys)}

Expand All @@ -215,7 +215,7 @@ defmodule Lua do
end
end)

case :luerl_new.set_table_keys_dec(keys, value, state) do
case :luerl.set_table_keys_dec(keys, value, state) do
{:ok, _value, state} ->
wrap(state)

Expand All @@ -225,7 +225,7 @@ defmodule Lua do
end

defp set_keys!(state, keys) do
case :luerl_new.set_table_keys_dec(keys, [], state) do
case :luerl.set_table_keys_dec(keys, [], state) do
{:ok, _, state} ->
{keys, state}

Expand Down Expand Up @@ -259,7 +259,7 @@ defmodule Lua do
"nested"
"""
def get!(%__MODULE__{state: state}, keys) do
case :luerl_new.get_table_keys_dec(keys, state) do
case :luerl.get_table_keys_dec(keys, state) do
{:ok, value, _state} ->
value

Expand All @@ -286,7 +286,7 @@ defmodule Lua do
def eval!(state \\ new(), script)

def eval!(%__MODULE__{state: state} = lua, script) when is_binary(script) do
case :luerl_new.do_dec(script, state) do
case :luerl.do_dec(script, state) do
{:ok, result, new_state} ->
{result, %__MODULE__{lua | state: new_state}}

Expand All @@ -312,7 +312,7 @@ defmodule Lua do
def eval!(%__MODULE__{} = lua, %Lua.Chunk{} = chunk) do
{chunk, lua} = load_chunk!(lua, chunk)

case :luerl_new.call_chunk(chunk.ref, lua.state) do
case :luerl.call_chunk(chunk.ref, lua.state) do
{:ok, result, new_state} ->
{result, %__MODULE__{lua | state: new_state}}

Expand Down Expand Up @@ -425,7 +425,7 @@ defmodule Lua do
when (is_list(args) and is_tuple(name)) or is_function(name) do
{ref, lua} = encode!(lua, name)

case :luerl_new.call(ref, args, lua.state) do
case :luerl.call(ref, args, lua.state) do
{:ok, value, state} -> {value, wrap(state)}
{:lua_error, _, _} = error -> raise Lua.RuntimeException, error
end
Expand All @@ -436,7 +436,7 @@ defmodule Lua do

func = get!(lua, keys)

case :luerl_new.call_function(func, args, lua.state) do
case :luerl.call_function(func, args, lua.state) do
{:ok, ret, lua} -> {ret, wrap(lua)}
{:lua_error, _, _} = error -> raise Lua.RuntimeException, error
end
Expand All @@ -450,7 +450,7 @@ defmodule Lua do
{:tref, 14}
"""
def encode!(%__MODULE__{} = lua, value) do
{encoded, state} = :luerl_new.encode(value, lua.state)
{encoded, state} = :luerl.encode(value, lua.state)
{encoded, wrap(state)}
rescue
ArgumentError ->
Expand All @@ -466,7 +466,7 @@ defmodule Lua do
"""
def decode!(%__MODULE__{} = lua, value) do
:luerl_new.decode(value, lua.state)
:luerl.decode(value, lua.state)
rescue
ArgumentError ->
reraise Lua.RuntimeException, "Failed to decode #{inspect(value)}", __STACKTRACE__
Expand All @@ -479,7 +479,7 @@ defmodule Lua do
Mimics the functionality of Lua's [dofile](https://www.lua.org/manual/5.4/manual.html#pdf-dofile)
"""
def load_file!(%__MODULE__{state: state} = lua, path) when is_binary(path) do
case :luerl_new.dofile(String.to_charlist(path), [:return], state) do
case :luerl.dofile(String.to_charlist(path), [:return], state) do
{:ok, _, state} ->
%__MODULE__{lua | state: state}

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule Lua.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:luerl, path: "../../oss/luerl"},
{:luerl, github: "rvirding/luerl", branch: "develop-encode"},
{:ex_doc, "~> 0.31", only: :dev, runtime: false}
]
end
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%{
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"ex_doc": {:hex, :ex_doc, "0.32.1", "21e40f939515373bcdc9cffe65f3b3543f05015ac6c3d01d991874129d173420", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5142c9db521f106d61ff33250f779807ed2a88620e472ac95dc7d59c380113da"},
"luerl": {:hex, :luerl, "1.2.3", "df25f41944e57a7c4d9ef09d238bc3e850276c46039cfc12b8bb42eccf36fcb1", [:rebar3], [], "hexpm", "1b4b9d0ca5d7d280d1d2787a6a5ee9f5a212641b62bff91556baa53805df3aed"},
"luerl": {:git, "https://github.com/rvirding/luerl.git", "7f1c5f41b65fa58ea4f0178b73fdd3771ca72d85", [branch: "develop-encode"]},
"makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.5", "e0ff5a7c708dda34311f7522a8758e23bfcd7d8d8068dc312b5eb41c6fd76eba", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "94d2e986428585a21516d7d7149781480013c56e30c6a233534bedf38867a59a"},
Expand Down

0 comments on commit 2e406de

Please sign in to comment.