-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Lua.parse_chunk/1 for runtime parsing of chunks (#44)
- Loading branch information
1 parent
ec21718
commit d5b9e05
Showing
5 changed files
with
98 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
```elixir | ||
Mix.install([ | ||
{:lua, "~> 0.0.16"} | ||
{:lua, "~> 0.0.17"} | ||
]) | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,41 @@ | ||
defmodule Lua.CompilerException do | ||
defexception [:message] | ||
defexception [:errors, :state] | ||
|
||
alias Lua.Util | ||
|
||
def exception(errors) when is_list(errors) do | ||
for error <- errors do | ||
Util.format_error(error) | ||
end | ||
def exception(formatted: errors) when is_list(errors) do | ||
%__MODULE__{errors: errors} | ||
end | ||
|
||
errors = Enum.map_join(errors, "\n", &Util.format_error/1) | ||
def exception(errors) when is_list(errors) do | ||
%__MODULE__{errors: Enum.map(errors, &Util.format_error/1)} | ||
end | ||
|
||
message = """ | ||
Failed to compile Lua! | ||
def exception({:lua_error, error, state}) do | ||
%__MODULE__{errors: [Util.format_error(error)], state: state} | ||
end | ||
|
||
#{errors} | ||
def exception({_line, _type, _failure} = error) do | ||
%__MODULE__{errors: [Util.format_error(error)]} | ||
end | ||
|
||
def message(%__MODULE__{state: nil, errors: errors}) do | ||
""" | ||
Failed to compile Lua! | ||
%__MODULE__{message: message} | ||
#{Enum.join(errors, "\n")} | ||
""" | ||
end | ||
|
||
def exception({:lua_error, error, state}) do | ||
def message(%__MODULE__{errors: errors, state: state}) do | ||
stacktrace = Luerl.New.get_stacktrace(state) | ||
|
||
message = """ | ||
Failed to compile Lua script! | ||
#{Util.format_error(error)} | ||
#{Util.format_stacktrace(stacktrace, state)} | ||
""" | ||
Failed to compile Lua! | ||
%__MODULE__{message: message} | ||
end | ||
|
||
def exception({_line, _type, _failure} = error) do | ||
message = """ | ||
Failed to compile Lua script! | ||
#{Enum.join(errors, "\n")} | ||
#{Util.format_error(error)} | ||
#{Util.format_stacktrace(stacktrace, state)} | ||
""" | ||
|
||
%__MODULE__{message: message} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters