I trying to write some game, based on Love2d framework, compiled from moonscript. Every time when I make a mistake in my code, my application throws error and this error refers to compiled lua-code, but not a moonscript, so I have no idea where exactly this error happens. Tell me please, what a solution in this situation? Thanks.
How to debug moonscript?
581 Views Asked by Beast Winterwolf AtThere are 2 best solutions below

Debugging is a problem for pretty much any source-to-source compilation system. The target language has no idea that the original language exists, so it can only talk about things in terms of the target language. The more divergent the target and original languages are, the more difficult debugging will be.
This is a big part of the reason why C++ compilers don't compile to C anymore.
The only real way to deal with this is to become intimately familiar with how the Moonscript compiler generates Lua from your Moonscript code. Learn Lua and carefully read the output Lua, comparing it to the given Moonscript. That will make it easier for you to map the given Lua error and source code to the actual Moonscript code that created it.
Moonscript does support source-mapping/error-rewriting, but it is only supported when running in the
moon
interpreter: https://moonscript.org/reference/command_line.html#error_rewritingI think it could be enabled in another lua environment but I am not completely sure what would be involved.
It would definetely require moonscript to hold on to the source-map tables that are created during compilation, so you couldn't use
moonc
; instead use themoonscript
module to just-in-time compile require'd modules:main.lua
init.moon
with this code and moonscript properly installed you can just run the project using
love .
as normal. Therequire 'moonscript'
call will changerequire
to compile moonscript modules on-the-fly. The performance penalty is negligible and after all modules have been loaded there is no difference.