diff options
author | Mateusz Czaplinski <mateusz@czaplinski.pl> | 2011-05-30 21:13:14 +0200 |
---|---|---|
committer | Mateusz Czaplinski <mateusz@czaplinski.pl> | 2011-05-30 21:13:14 +0200 |
commit | 6c11ccf4a6c7e7a2a6eb79b2453f6d2e6a7a2dec (patch) | |
tree | ac948e76b3a2cdc497db9994246321fa939509d1 | |
parent | e2adeb9e242ae2824500acf2a3410c10fd2ebb81 (diff) | |
download | luacov-6c11ccf4a6c7e7a2a6eb79b2453f6d2e6a7a2dec.tar.gz |
luacov.lua: dropped 'module()', improved code locality
-rw-r--r-- | src/luacov.lua | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/src/luacov.lua b/src/luacov.lua index 166c8be..63a178e 100644 --- a/src/luacov.lua +++ b/src/luacov.lua @@ -1,14 +1,14 @@ -module("luacov", package.seeall) +local M = {} local stats = require("luacov.stats") +local data = stats.load() +local statsfile = stats.start() +M.statsfile = statsfile -data = stats.load() - -statsfile = stats.start() - -tick = package.loaded["luacov.tick"] -ctr = 0 +local tick = package.loaded["luacov.tick"] +local ctr = 0 +local luacovlock = os.tmpname() local function on_line(_, line_nr) if tick then @@ -40,44 +40,45 @@ local function on_line(_, line_nr) end end -local luacovlock = os.tmpname() - -function on_exit() +local function on_exit() os.remove(luacovlock) stats.save(data, statsfile) stats.stop(statsfile) end -if not tick then - on_exit_trick = io.open(luacovlock, "w") - debug.setmetatable(on_exit_trick, { __gc = on_exit } ) -end - -debug.sethook(on_line, "l") +local function init() + if not tick then + M.on_exit_trick = io.open(luacovlock, "w") + debug.setmetatable(M.on_exit_trick, { __gc = on_exit } ) + end -rawcoroutinecreate = coroutine.create + debug.sethook(on_line, "l") -function coroutine.create(...) - local co = rawcoroutinecreate(...) - debug.sethook(co, on_line, "l") - return co -end + local rawcoroutinecreate = coroutine.create + coroutine.create = function(...) + local co = rawcoroutinecreate(...) + debug.sethook(co, on_line, "l") + return co + end + coroutine.wrap = function(...) + local co = rawcoroutinecreate(...) + debug.sethook(co, on_line, "l") + return function() + local r = { coroutine.resume(co) } + if not r[1] then + error(r[2]) + end + return unpack(r, 2) + end + end -function coroutine.wrap(...) - local co = rawcoroutinecreate(...) - debug.sethook(co, on_line, "l") - return function() - local r = { coroutine.resume(co) } - if not r[1] then - error(r[2]) - end - return unpack(r, 2) - end + local rawexit = os.exit + os.exit = function(...) + on_exit() + rawexit(...) + end end +init() -local rawexit = os.exit -function os.exit(...) - on_exit() - rawexit(...) -end
\ No newline at end of file +return M
|