1

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.

Beast Winterwolf
  • 229
  • 2
  • 11

2 Answers2

1

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Actually, this is not exactly what I was hoping to hear, but thanks for the answer. It is unfortunate that moonscript does not support any source mapping technology, like coffeescript. – Beast Winterwolf Oct 14 '18 at 17:12
1

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_rewriting

I 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 the moonscript module to just-in-time compile require'd modules:

main.lua

-- attempt to require moonscript,
-- for development
pcall(require, 'moonscript')

-- load the main file
require 'init'

init.moon

love.draw = ->
  print "test"

with this code and moonscript properly installed you can just run the project using love . as normal. The require 'moonscript' call will change require to compile moonscript modules on-the-fly. The performance penalty is negligible and after all modules have been loaded there is no difference.

s-ol
  • 1,674
  • 17
  • 28
  • Sorry, I'm so slowpoke. I had a certain build system and I no longer wanted to change it, which is why I abandoned moonscript. But now I decided to come back, checked your decision and it is just perfect! Thank you very much! – Beast Winterwolf Jun 23 '19 at 06:50
  • Damn! I just found problem in your solution - errors refers to right files, but wrong line numbers :( – Beast Winterwolf Jun 23 '19 at 15:23
  • that's what I mentioned above. You can simply compile the file the error is from using `moonc` and see what is going on there. Also, as I mentioned there *are* sourcemaps, they just can't really be integrated into love apparently. – s-ol Jun 23 '19 at 18:23