Changeset

4680:8834f220ab91

util.debug: Turn into a real-ish module ('debugx'), and require you call use() to override debug.traceback()
author Matthew Wild <mwild1@gmail.com>
date Tue, 24 Apr 2012 18:53:50 +0100
parents 4679:5b52b5eaa03d
children 4681:3299223bbed5
files util/debug.lua
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/util/debug.lua	Tue Apr 24 18:50:22 2012 +0100
+++ b/util/debug.lua	Tue Apr 24 18:53:50 2012 +0100
@@ -8,7 +8,9 @@
 	pwd = true;
 };
 
-local function get_locals_table(level)
+module("debugx", package.seeall);
+
+function get_locals_table(level)
 	level = level + 1; -- Skip this function itself
 	local locals = {};
 	for local_num = 1, math.huge do
@@ -19,7 +21,7 @@
 	return locals;
 end
 
-local function get_upvalues_table(func)
+function get_upvalues_table(func)
 	local upvalues = {};
 	if func then
 		for upvalue_num = 1, math.huge do
@@ -31,7 +33,7 @@
 	return upvalues;
 end
 
-local function string_from_var_table(var_table, max_line_len, indent_str)
+function string_from_var_table(var_table, max_line_len, indent_str)
 	local var_string = {};
 	local col_pos = 0;
 	max_line_len = max_line_len or math.huge;
@@ -88,7 +90,7 @@
 	return levels;
 end
 
-function debug.traceback(thread, message, level)
+function traceback(thread, message, level)
 	if type(thread) ~= "thread" then
 		thread, message, level = coroutine.running(), thread, message;
 	end
@@ -136,3 +138,9 @@
 	end
 	return message.."stack traceback:\n"..table.concat(lines, "\n");
 end
+
+function use()
+	debug.traceback = traceback;
+end
+
+return _M;