diff options
author | Mateusz Czaplinski <mateusz@czaplinski.pl> | 2011-05-30 21:00:38 +0200 |
---|---|---|
committer | Mateusz Czaplinski <mateusz@czaplinski.pl> | 2011-05-30 21:00:38 +0200 |
commit | 819ffb727005b8093000579745074e61d12f0c17 (patch) | |
tree | b7265b92173d58f912f02ed3c91c3e94f9cc9ace | |
parent | b641b3f51c074a959ef0395452e33a185c255c69 (diff) | |
download | luacov-819ffb727005b8093000579745074e61d12f0c17.tar.gz |
luacov/stats.lua: Dropped 'module' in favour of 'local M={}' pattern +
other locality improvements
-rwxr-xr-x | src/bin/luacov | 2 | ||||
-rw-r--r-- | src/luacov.lua | 10 | ||||
-rw-r--r-- | src/luacov/stats.lua | 13 |
3 files changed, 14 insertions, 11 deletions
diff --git a/src/bin/luacov b/src/bin/luacov index 5eb912d..1a22947 100755 --- a/src/bin/luacov +++ b/src/bin/luacov @@ -2,7 +2,7 @@ local luacov = require("luacov.stats") -local data, most_hits = luacov.load_stats() +local data, most_hits = luacov.load() if not data then print("Could not load stats file "..luacov.statsfile..".") diff --git a/src/luacov.lua b/src/luacov.lua index a2334e3..166c8be 100644 --- a/src/luacov.lua +++ b/src/luacov.lua @@ -3,9 +3,9 @@ module("luacov", package.seeall) local stats = require("luacov.stats") -data = stats.load_stats() +data = stats.load() -statsfile = stats.start_stats() +statsfile = stats.start() tick = package.loaded["luacov.tick"] ctr = 0 @@ -15,7 +15,7 @@ local function on_line(_, line_nr) ctr = ctr + 1 if ctr == 100 then ctr = 0 - stats.save_stats(data, statsfile) + stats.save(data, statsfile) end end @@ -44,8 +44,8 @@ local luacovlock = os.tmpname() function on_exit() os.remove(luacovlock) - stats.save_stats(data, statsfile) - stats.stop_stats(statsfile) + stats.save(data, statsfile) + stats.stop(statsfile) end if not tick then diff --git a/src/luacov/stats.lua b/src/luacov/stats.lua index 3fa5916..1e50eec 100644 --- a/src/luacov/stats.lua +++ b/src/luacov/stats.lua @@ -1,9 +1,10 @@ -module("luacov.stats", package.seeall) +local M = {} local statsfile = "luacov.stats.out" +local stats -function load_stats() +function M.load() local data, most_hits = {}, 0 local stats = io.open(statsfile, "r") if not stats then return data end @@ -31,15 +32,15 @@ function load_stats() return data, most_hits end -function start_stats() +function M.start() return io.open(statsfile, "w") end -function stop_stats(stats) +function M.stop(stats) stats:close() end -function save_stats(data, stats) +function M.save(data, stats) stats:seek("set") for filename, filedata in pairs(data) do local max = filedata.max @@ -55,3 +56,5 @@ function save_stats(data, stats) end stats:flush() end + +return M |