Comparison

net/connlisteners.lua @ 4220:05f4db0459b1

net.connlisteners: Log traceback on errors in listener loading.
author Waqas Hussain <waqas20@gmail.com>
date Wed, 02 Mar 2011 05:11:42 +0500
parent 3540:bc139431830b
child 4322:aff627b1ce95
comparison
equal deleted inserted replaced
4218:8a271b3fcaa7 4220:05f4db0459b1
11 local listeners_dir = (CFG_SOURCEDIR or ".").."/net/"; 11 local listeners_dir = (CFG_SOURCEDIR or ".").."/net/";
12 local server = require "net.server"; 12 local server = require "net.server";
13 local log = require "util.logger".init("connlisteners"); 13 local log = require "util.logger".init("connlisteners");
14 local tostring = tostring; 14 local tostring = tostring;
15 15
16 local dofile, pcall, error = 16 local dofile, xpcall, error =
17 dofile, pcall, error 17 dofile, xpcall, error
18
19 local debug_traceback = debug.traceback;
18 20
19 module "connlisteners" 21 module "connlisteners"
20 22
21 local listeners = {}; 23 local listeners = {};
22 24
35 end 37 end
36 38
37 function get(name) 39 function get(name)
38 local h = listeners[name]; 40 local h = listeners[name];
39 if not h then 41 if not h then
40 local ok, ret = pcall(dofile, listeners_dir..name:gsub("[^%w%-]", "_").."_listener.lua"); 42 local ok, ret = xpcall(function() dofile(listeners_dir..name:gsub("[^%w%-]", "_").."_listener.lua") end, debug_traceback);
41 if not ok then 43 if not ok then
42 log("error", "Error while loading listener '%s': %s", tostring(name), tostring(ret)); 44 log("error", "Error while loading listener '%s': %s", tostring(name), tostring(ret));
43 return nil, ret; 45 return nil, ret;
44 end 46 end
45 h = listeners[name]; 47 h = listeners[name];