diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-03-21 12:00:17 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-03-21 12:28:38 +0000 |
| commit | f5776f95ea3ae5b76c12cca96c00914f5d43eed0 (patch) | |
| tree | d544acd4f2d08d4bab8bc8a7fe2c539d4af713e4 | |
| parent | language Error tracking (diff) | |
| download | alive-f5776f95ea3ae5b76c12cca96c00914f5d43eed0.tar.gz alive-f5776f95ea3ae5b76c12cca96c00914f5d43eed0.zip | |
luajit compatibility
| -rw-r--r-- | core/builtin.moon | 2 | ||||
| -rw-r--r-- | core/error.moon | 15 | ||||
| -rw-r--r-- | init.moon | 10 |
3 files changed, 23 insertions, 4 deletions
diff --git a/core/builtin.moon b/core/builtin.moon index 3e4787c..49de80f 100644 --- a/core/builtin.moon +++ b/core/builtin.moon @@ -214,7 +214,7 @@ prints expr's value whenever it changes." op = Value 'opdef', traceOp tag = @tag\clone Tag.parse '-1' - prefix = Value.str tail[1]\stringify! + prefix = Value.str tostring tail[1] op_invoke\eval_cell scope, tag, op, { prefix, tail[1] } { diff --git a/core/error.moon b/core/error.moon index a06c359..e72cc5f 100644 --- a/core/error.moon +++ b/core/error.moon @@ -2,6 +2,9 @@ -- Language error and traceback. -- -- @classmod Error + +unpack or= table.unpack + class Error --- members -- @section members @@ -14,7 +17,13 @@ class Error -- @tparam string where add_frame: (where) => @trace ..= "\n while #{where}" - __tostring: => "#{@kind} error: #{@message}#{@detail}#{@trace}" + __tostring: => + str = "#{@kind} error: #{@message}" + if @detail + str ..= "\n#{@detail}" + if @trace + str ..= @trace + str --- static functions -- @section static @@ -33,13 +42,13 @@ class Error -- @tparam string message -- @tparam ?string detail new: (@kind, @message, @detail) => - @trace = "" + @trace = '' handler = (err) -> if err.__class == Error err else - Error 'implementation', err, debug.traceback 'Lua error below:', 2 + Error 'implementation', err, debug.traceback "Lua error below:", 2 --- Wrap function errors in a traceback frame. -- -- Execute `fn(...)`, and turn any error thrown as a result into an @@ -1,3 +1,13 @@ +if _VERSION == 'Lua 5.1' + package.path ..= ';./?/init.lua' + package.moonpath ..= ';./?/init.moon' + + export assert + assert = (a, msg, ...) -> + if not a + error msg + a, msg, ... + -- run from CLI import Logger from require 'logger' import Copilot from require 'copilot' |
