leafo / moonscript

:crescent_moon: A language that compiles to Lua
https://moonscript.org
3.18k stars 189 forks source link

Error rewriting api #106

Open enomado opened 11 years ago

enomado commented 11 years ago

Hi. I want to call moonscript from binary executable and luajit. I try to do same that moon loader do i.e.

    xpcall run, (_err) ->
        err = _err
        trace = debug.traceback("", 2)

    if err
        truncated = errors.truncate_traceback(util.trim(trace))
        rewritten = errors.rewrite_traceback(truncated, err)

but rewritten is always nil.

it would be nice if there were such a helper for running moonscript code from any place with error rewriting.

tmandry commented 9 years ago

+1, one of the main features of Lua is embeddability and by not having error rewriting outside the CLI, it makes it too difficult to use Moonscript in many of the places you would use Lua.

In my case, I want to use it in Hammerspoon and could add direct support in the source if needed.

tgoyne commented 9 years ago

I went with writing a custom stack trace generator that manually uses the moonscript line tables for .moon files: https://github.com/Aegisub/Aegisub/blob/master/libaegisub/lua/utils.cpp#L127

tmandry commented 9 years ago

@tgoyne Brilliant, thanks for sharing!

buckle2000 commented 7 years ago

LuaJIT just not works with moonscript