new feature: Keep line number
Well, I would like to keep line numbere when compling. In this way, luajit can also display the correct line number in stacktrace.
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!
I think I fixed it. I really don't have time for this now.
Can confirm this works for me too, thanks @buckle2000
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", {
Wow, this pull request is really old. @leafo is there any change you will merge this?
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
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.
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