summaryrefslogtreecommitdiff
path: root/tools/rewrite.lua
blob: e26a8c30904c45bf4c8ac57a8e690ed62829cd60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
--[[Script to rewrite a stack traceback in terms of moonscript instead of lua]]

for data in io.lines() do
	local spaces, filename, linenum, rest = data:gmatch("(%s*)(.*%.lua):(%d+):(.*)")()
	if filename and linenum and rest then
		local moonfilename = filename:gsub(".lua$",".moon")

		--If our file is not moonscript, we won't have a debug file
		local debugfile, err = io.open(filename .. ".X", "r")
		if not debugfile then
			--print("not debugfile" .. filename .. ":" .. err)
			print(data)
			goto next
		end

		--Skip first line
		debugfile:read("*l")
		for line in debugfile:lines() do
			_,_,pos,lua,moon = line:find("(%d+)%s+(%d+):%b[] >> (%d+)")
			if tonumber(linenum) == tonumber(lua) then
				print(string.format("%s%s:%d: %s",spaces,moonfilename,moon,rest))
				goto next
			end
		end
		debugfile:close()
	else
		print(data)
	end
	::next::
end