From 1f95825a1e69365a9ec1c4a38cda379c73a8666c Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 22 Oct 2010 14:49:12 +0200 Subject: [PATCH] gears.debug: Import So far this only contains an "assert()" function, but I guess this could be enhance. For example, a function which pretty-prints a table's contents might be useful to have. Signed-off-by: Uli Schlachter --- lib/gears/debug.lua.in | 23 +++++++++++++++++++++++ lib/gears/init.lua.in | 1 + 2 files changed, 24 insertions(+) create mode 100644 lib/gears/debug.lua.in diff --git a/lib/gears/debug.lua.in b/lib/gears/debug.lua.in new file mode 100644 index 000000000..2f14d9b68 --- /dev/null +++ b/lib/gears/debug.lua.in @@ -0,0 +1,23 @@ +--------------------------------------------------------------------------- +-- @author Uli Schlachter +-- @copyright 2010 Uli Schlachter +-- @release @AWESOME_VERSION@ +--------------------------------------------------------------------------- + +local error = error +local tostring = tostring +local traceback = debug.traceback + +module("gears.debug") + +--- Check that the given condition holds true, else throw an error +-- @param cond If this is false, throw a lua error with a backtrace. +-- @param message Message to print in the error (optional). +function assert(cond, message) + local message = message or cond + if not cond then + error(traceback("Assertion failed: '" .. tostring(message) .. "'")) + end +end + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/lib/gears/init.lua.in b/lib/gears/init.lua.in index b53b2aa44..4b7c5a3b4 100644 --- a/lib/gears/init.lua.in +++ b/lib/gears/init.lua.in @@ -5,6 +5,7 @@ --------------------------------------------------------------------------- require("gears.color") +require("gears.debug") require("gears.object") require("gears.sort")