tools/ejabberdsql2prosody: Track current line for error reporting
authorMatthew Wild <mwild1@gmail.com>
Tue, 20 Sep 2011 23:30:58 +0100
changeset 4384 7fbcb7e6a6a0
parent 4383 718445c040c4
child 4385 c94167139f27
tools/ejabberdsql2prosody: Track current line for error reporting
tools/ejabberdsql2prosody.lua
--- a/tools/ejabberdsql2prosody.lua	Wed Sep 21 03:25:34 2011 +0500
+++ b/tools/ejabberdsql2prosody.lua	Tue Sep 20 23:30:58 2011 +0100
@@ -21,12 +21,16 @@
 
 local file = nil;
 local last = nil;
+local line = 1;
 local function read(expected)
 	local ch;
 	if last then
 		ch = last; last = nil;
-	else ch = file:read(1); end
-	if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil")); end
+	else
+		ch = file:read(1);
+		if ch == "\n" then line = line + 1; end
+	end
+	if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil").." on line "..line); end
 	return ch;
 end
 local function pushback(ch)