diff --git a/lib/lua.ex b/lib/lua.ex index 47226f1..9eb7993 100644 --- a/lib/lua.ex +++ b/lib/lua.ex @@ -92,7 +92,7 @@ defmodule Lua do end chunk = - case :luerl_comp.string(String.to_charlist(code), [:return]) do + case :luerl_comp.string(code, [:return]) do {:ok, chunk} -> %Lua.Chunk{instructions: chunk} {:error, error, _warnings} -> raise Lua.CompilerException, error end @@ -285,11 +285,19 @@ defmodule Lua do end end - defp illegal_index([:_G | keys]), do: illegal_index(keys) defp illegal_index(["_G" | keys]), do: illegal_index(keys) defp illegal_index(keys) do - {:illegal_index, nil, Enum.join(keys, ".")} + {:illegal_index, nil, + keys + |> Enum.map(fn key -> + if(is_tuple(key)) do + inspect(key) + else + key + end + end) + |> Enum.join(".")} end @doc """ @@ -369,10 +377,6 @@ defmodule Lua do def eval!(%__MODULE__{state: state} = lua, script, opts) when is_binary(script) do opts = Keyword.validate!(opts, decode: true) - # Luerl does some weird things with UTF8 encoding - # when its a binary see https://github.com/rvirding/luerl/issues/197 - script = String.to_charlist(script) - func = if opts[:decode] do &:luerl.do_dec/2 @@ -451,8 +455,6 @@ defmodule Lua do """ def parse_chunk(code) do - code = String.to_charlist(code) - case :luerl_comp.string(code, [:return]) do {:ok, chunk} -> {:ok, %Lua.Chunk{instructions: chunk}} diff --git a/mix.exs b/mix.exs index 2df7b63..d7fd8c3 100644 --- a/mix.exs +++ b/mix.exs @@ -55,7 +55,7 @@ defmodule Lua.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:luerl, "~> 1.4.1"}, + {:luerl, "~> 1.5.0"}, {:ex_doc, "~> 0.38", only: :dev, runtime: false}, {:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false} ] diff --git a/mix.lock b/mix.lock index 0f36d7b..53f72e2 100644 --- a/mix.lock +++ b/mix.lock @@ -3,7 +3,7 @@ "earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"}, "erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"}, "ex_doc": {:hex, :ex_doc, "0.38.1", "bae0a0bd5b5925b1caef4987e3470902d072d03347114ffe03a55dbe206dd4c2", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "754636236d191b895e1e4de2ebb504c057fe1995fdfdd92e9d75c4b05633008b"}, - "luerl": {:hex, :luerl, "1.4.1", "0018b5002849a3ba401bc2dc5a67e45de4c404aacfd1b9d3c2fc50fde599ff12", [:rebar3], [], "hexpm", "618ff8967d23d8f8d5800a3784625aeafba7fa42648fd9af4f05fcd1383cb860"}, + "luerl": {:hex, :luerl, "1.5.0", "9573d6768eaec3c752f4e45d52217a4633d73ee45f95d992f53fa425f62b1fd7", [:rebar3], [], "hexpm", "76612d8b94a93f622f483e90a4d277a007590e12dceb9b35c8ff4be32d644484"}, "makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"}, "makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [: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", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"}, "makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"}, diff --git a/test/lua_test.exs b/test/lua_test.exs index cb11d70..40f188d 100644 --- a/test/lua_test.exs +++ b/test/lua_test.exs @@ -47,7 +47,7 @@ defmodule LuaTest do message = """ Failed to compile Lua! - Failed to tokenize: illegal token on line 1: \"hi) + Line 1: syntax error near '<\\34>' """ assert_raise Lua.CompilerException, message, fn -> @@ -121,8 +121,7 @@ defmodule LuaTest do error = """ Failed to compile Lua! - Failed to tokenize: illegal token on line 1: ' - + Line 1: syntax error near '<\\39>' """ assert_raise Lua.CompilerException, error, fn -> @@ -666,8 +665,7 @@ defmodule LuaTest do error = """ Failed to compile Lua! - Failed to tokenize: illegal token on line 1: ") - + Line 1: syntax error near '<\\34>' """ assert_raise Lua.CompilerException, error, fn -> @@ -679,8 +677,7 @@ defmodule LuaTest do error = """ Failed to compile Lua! - Failed to tokenize: illegal token on line 1: "yuup) - + Line 1: syntax error near '<\\34>' """ assert_raise Lua.CompilerException, error, fn ->