2014-11-14 15:33:52 +00:00
|
|
|
local dump = require("dump")
|
2014-05-26 15:38:51 +00:00
|
|
|
local isAndroid, android = pcall(require, "android")
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local Dbg = {
|
2014-03-13 13:52:43 +00:00
|
|
|
is_on = false,
|
|
|
|
ev_log = nil,
|
2013-03-12 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local Dbg_mt = {}
|
|
|
|
|
|
|
|
local function LvDEBUG(lv, ...)
|
2014-03-13 13:52:43 +00:00
|
|
|
local line = ""
|
|
|
|
for i,v in ipairs({...}) do
|
|
|
|
if type(v) == "table" then
|
2014-11-14 15:33:52 +00:00
|
|
|
line = line .. " " .. dump(v, lv)
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
|
|
|
line = line .. " " .. tostring(v)
|
|
|
|
end
|
|
|
|
end
|
2014-05-26 15:38:51 +00:00
|
|
|
if isAndroid then
|
|
|
|
android.LOGI("#"..line)
|
|
|
|
else
|
|
|
|
print("#"..line)
|
2014-10-18 13:31:05 +00:00
|
|
|
io.stdout:flush()
|
2014-05-26 15:38:51 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Dbg_mt.__call(dbg, ...)
|
2014-03-13 13:52:43 +00:00
|
|
|
if dbg.is_on then LvDEBUG(math.huge, ...) end
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
2013-03-12 17:18:53 +00:00
|
|
|
function Dbg:turnOn()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.is_on = true
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
-- create or clear ev log file
|
2014-05-28 04:57:53 +00:00
|
|
|
self.ev_log = io.open("ev.log", "w")
|
2013-03-12 17:18:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Dbg:logEv(ev)
|
2014-03-13 13:52:43 +00:00
|
|
|
local log = ev.type.."|"..ev.code.."|"
|
|
|
|
..ev.value.."|"..ev.time.sec.."|"..ev.time.usec.."\n"
|
|
|
|
self.ev_log:write(log)
|
|
|
|
self.ev_log:flush()
|
2013-03-12 17:18:53 +00:00
|
|
|
end
|
|
|
|
|
2013-10-25 12:07:58 +00:00
|
|
|
function Dbg:traceback()
|
2014-03-13 13:52:43 +00:00
|
|
|
LvDEBUG(math.huge, debug.traceback())
|
2013-10-25 12:07:58 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
setmetatable(Dbg, Dbg_mt)
|
2013-03-15 09:01:34 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return Dbg
|