Software /
code /
prosody
Comparison
util/helpers.lua @ 1531:21051377f11b
util.helpers: New util library to aid with debugging, etc.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 12 Jul 2009 02:07:14 +0100 |
child | 1795:0e933d6f2c31 |
comparison
equal
deleted
inserted
replaced
1530:0494f5e3be23 | 1531:21051377f11b |
---|---|
1 | |
2 module("helpers", package.seeall); | |
3 | |
4 -- Helper functions for debugging | |
5 | |
6 local log = require "util.logger".init("util.debug"); | |
7 | |
8 function log_events(events, name, logger) | |
9 local f = events.fire_event; | |
10 if not f then | |
11 error("Object does not appear to be a util.events object"); | |
12 end | |
13 logger = logger or log; | |
14 name = name or tostring(events); | |
15 function events.fire_event(event, ...) | |
16 logger("debug", "%s firing event: %s", name, event); | |
17 end | |
18 events[events.fire_event] = f; | |
19 return events; | |
20 end | |
21 | |
22 function revert_log_events(events) | |
23 events.fire_event, events[events.fire_event] = events[events.fire_event], nil; -- :) | |
24 end | |
25 | |
26 return _M; |