Skip to content

Commit

Permalink
Fix calls to error/1
Browse files Browse the repository at this point in the history
  • Loading branch information
davydog187 committed Mar 7, 2024
1 parent e60e38d commit 29f969a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/lua/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ defmodule Lua.Util do
nil -> " <unknown function>#{format_args(args)}"
"-no-name-" -> ""
{:luerl_lib_basic, :basic_error} -> format_error(func, args)
{:luerl_lib_basic, :basic_error, :undefined} -> format_error(func, args)
func -> " #{format_function([func], args)}"
end

Expand Down Expand Up @@ -127,6 +128,10 @@ defmodule Lua.Util do
format_function("error", args)
end

defp format_error({:luerl_lib_basic, :basic_error, :undefined}, args) do
format_function("error", args)
end

defp format_error(_, {:undefined, args}) do
format_function("unknown_error", args)
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Lua.MixProject do
use Mix.Project

@url "https://github.com/tv-labs/lua"
@version "0.0.1"
@version "0.0.2"

def project do
[
Expand Down
16 changes: 16 additions & 0 deletions test/lua_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ defmodule LuaTest do
""")
end
end

test "error/1 raises an exception" do
error = """
Lua runtime error: error("this is an error")
script line 1:error("this is an error")
"""

assert_raise Lua.RuntimeException, error, fn ->
lua = Lua.new(sandboxed: [])

Lua.eval!(lua, """
error("this is an error")
""")
end
end
end

describe "set!/2 and get!/2" do
Expand Down

0 comments on commit 29f969a

Please sign in to comment.