forked from pkulchenko/ZeroBranePackage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
realtimewatch.lua
49 lines (42 loc) · 1.35 KB
/
realtimewatch.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
local redirect, filter = {}
local stats = {}
return {
name = "Real-time watches",
description = "Displays real-time values during debugging.",
author = "Paul Kulchenko",
version = 0.3,
dependencies = "1.40",
onRegister = function()
local config = ide:GetConfig()
redirect = config.debugger.redirect
filter = config.debugger.outputfilter
config.debugger.redirect = "r"
config.debugger.outputfilter = function(s)
local label, value = s:match('"(.-)%s*=%s*"\t(.+)')
if not label or not value then return s end
local num = tonumber(value)
-- for numbers report min/max/count/avg
if num then
stats[label] = stats[label] or {}
-- count, sum, min, max
local stat = stats[label]
stat[1] = (stat[1] or 0) + 1
stat[2] = (stat[2] or 0) + num
stat[3] = math.min(stat[3] or math.huge, num)
stat[4] = math.max(stat[4] or -math.huge, num)
value = ("%s (min: %s, max: %s, cnt: %s, avg: %s)")
:format(num, stat[3], stat[4], stat[1], stat[2]/stat[1])
end
ide:AddWatch(label, (value:gsub("\t", "; ")))
return
end
end,
onUnRegister = function(self)
local config = ide:GetConfig()
config.debugger.redirect = redirect
config.debugger.outputfilter = filter
end,
onDebuggerLoad = function(self)
stats = {}
end,
}