Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/trepl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClement Farabet <clement.farabet@gmail.com>2014-07-05 20:32:39 +0400
committerClement Farabet <clement.farabet@gmail.com>2014-07-05 20:32:39 +0400
commit734c159c01c9f214ffd65a54d6d227ea71b073b0 (patch)
tree9015d9befed7f087dab905b40c7325b25e899be9
parent8b35f2146a42a89013e9f0f27f0f605288995b51 (diff)
More advanced globals tracker.
-rw-r--r--init.lua26
1 files changed, 24 insertions, 2 deletions
diff --git a/init.lua b/init.lua
index 087fddc..d8f1702 100644
--- a/init.lua
+++ b/init.lua
@@ -310,24 +310,46 @@ end
-- Monitor Globals
function monitor_G(cb)
+ -- Force load of penlight packages:
+ stringx = require 'pl.stringx'
+ tablex = require 'pl.tablex'
+ path = require 'pl.path'
+ dir = require 'pl.dir'
+
+ -- Store current globals:
local evercreated = {}
for k in pairs(_G) do
evercreated[k] = true
end
+
+ -- Overwrite global namespace meta tables to monitor it:
setmetatable(_G, {
__newindex = function(G,key,val)
if not evercreated[key] then
if cb then
cb(key)
else
- print('created a global variable: ' .. key)
+ local file = debug.getinfo(2).source:gsub('^@','')
+ local line = debug.getinfo(2).currentline
+ if line > 0 then
+ print(colors.red .. 'created global variable: '
+ .. colors.blue .. key .. colors.none
+ .. ' @ ' .. colors.magenta .. file .. colors.none
+ .. ':' .. colors.green .. line .. colors.none
+ )
+ else
+ print(colors.red .. 'created global variable: '
+ .. colors.blue .. key .. colors.none
+ .. ' @ ' .. colors.yellow .. '[C-module]' .. colors.none
+ )
+ end
end
end
evercreated[key] = true
rawset(G,key,val)
end,
__index = function (table, key)
- error("attempt to read undeclared variable "..key, 2)
+ error(colors.red .. "attempt to read undeclared variable " .. colors.blue .. key .. colors.none, 2)
end,
})
end