moonscript icon indicating copy to clipboard operation
moonscript copied to clipboard

new feature: Keep line number

Open buckle2000 opened this issue 9 years ago • 8 comments

Well, I would like to keep line numbere when compling. In this way, luajit can also display the correct line number in stacktrace.

buckle2000 avatar Dec 09 '16 13:12 buckle2000

This feature is quite useful, I like it! 👍 I noticed that the help info for moonc is missing the necessary parameter for using this. Could you take a look @buckle2000 ? 😃

@leafo could you review this PR, please? I'm not sure if anything else is missing!

ThaisRobba avatar Aug 11 '17 04:08 ThaisRobba

I think I fixed it. I really don't have time for this now.

buckle2000 avatar Aug 11 '17 05:08 buckle2000

Can confirm this works for me too, thanks @buckle2000

svermeulen avatar Oct 14 '18 16:10 svermeulen

I should mention that I also had to add an 'n' to the list of characters this line local opts, ind = alt_getopt.get_opts(arg, "lvhwt:o:pTXb", {

svermeulen avatar Dec 24 '18 06:12 svermeulen

Wow, this pull request is really old. @leafo is there any change you will merge this?

buckle2000 avatar Dec 29 '18 00:12 buckle2000

In case anyone else uses this, I should mention that I updated @buckle2000 's branch with the leafo/master and put it here: https://github.com/svermeulen/moonscript/tree/keep_line_number

svermeulen avatar Mar 17 '19 22:03 svermeulen

I was scratching my head trying to debug using this branch. Classes don't seem to work well with this concept, given Moonscript's implementation of them. Since the constructor is added in postfix, I don't think it's possible to get the Moonscript source lined up properly. Aside from that, classes seem to love to merge themselves into other lines:

f1 = ->
  "Hello world!"

class Test
  new: (value) =>
    @index = value

  func: (var) =>
    print var

class Test2
  new: =>
    print f1!

f2 = ->
  var = "I'm a function!"
  print var

becomes

local f1 f1 = function()
  return "Hello world!" end local Test do   local _class_0   local _base_0 = {     func = function(self, var)






      return print(var)     end   }   _base_0.__index = _base_0   _class_0 = setmetatable({     __init = function(self, value)       self.index = value     end,     __base = _base_0,     __name = "Test"   }, {     __index = _base_0,     __call = function(cls, ...)       local _self_0 = setmetatable({}, _base_0)       cls.__init(_self_0, ...)       return _self_0     end   })   _base_0.__class = _class_0   Test = _class_0 end local Test2 do   local _class_0   local _base_0 = { }   _base_0.__index = _base_0   _class_0 = setmetatable({     __init = function(self)



      return print(f1())     end,     __base = _base_0,     __name = "Test2"   }, {     __index = _base_0,     __call = function(cls, ...)       local _self_0 = setmetatable({}, _base_0)       cls.__init(_self_0, ...)       return _self_0     end   })   _base_0.__class = _class_0   Test2 = _class_0 end

local f2 f2 = function()
  local var = "I'm a function!"
  return print(var) end

I think this will require a lot more work than anticipated.

wu4 avatar Apr 01 '19 21:04 wu4

Yeah, I've been using this for awhile and have noticed that it isn't perfect. It can often be off a couple lines. But for my purposes it's significantly better than having to search through the generated lua manually

svermeulen avatar Apr 01 '19 21:04 svermeulen