From 67de987aa9e60bf263e0d1bc8a34a203e88a7447 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Thu, 21 Oct 2010 23:27:00 +0200 Subject: beta 2010.10.21 23:27 --- scripts/context/lua/mtxrun.lua | 21 +++++++++++++++++++-- scripts/context/stubs/mswin/mtxrun.lua | 21 +++++++++++++++++++-- scripts/context/stubs/unix/mtxrun | 21 +++++++++++++++++++-- 3 files changed, 57 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index c678597e1..60a44bd2a 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -1110,8 +1110,14 @@ local function serialize(root,name,_handle,_reduce,_noquotes,_hexify) else handle("t={") end - if root and next(root) then - do_serialize(root,name,"",0) + if root then + -- The dummy access will initialize a table that has a delayed initialization + -- using a metatable. + local dummy = root.whatever + -- Let's forget about empty tables. + if next(root) then + do_serialize(root,name,"",0) + end end handle("}") end @@ -4062,6 +4068,16 @@ function getmetatablekey(t,key,value) end +function storage.setinitializer(data,initialize) + local m = getmetatable(data) or { } + m.__index = function(data,k) + m.__index = nil -- so that we can access the entries during initializing + initialize() + return data[k] + end + setmetatable(data, m) +end + end -- of closure @@ -4190,6 +4206,7 @@ function statistics.show(reporter) local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0 return format("direct: %s, indirect: %s, total: %s", total-indirect, indirect, total) end) + collectgarbage("collect") register("current memory usage", statistics.memused) register("runtime",statistics.runtime) for i=1,#statusinfo do diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index c678597e1..60a44bd2a 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -1110,8 +1110,14 @@ local function serialize(root,name,_handle,_reduce,_noquotes,_hexify) else handle("t={") end - if root and next(root) then - do_serialize(root,name,"",0) + if root then + -- The dummy access will initialize a table that has a delayed initialization + -- using a metatable. + local dummy = root.whatever + -- Let's forget about empty tables. + if next(root) then + do_serialize(root,name,"",0) + end end handle("}") end @@ -4062,6 +4068,16 @@ function getmetatablekey(t,key,value) end +function storage.setinitializer(data,initialize) + local m = getmetatable(data) or { } + m.__index = function(data,k) + m.__index = nil -- so that we can access the entries during initializing + initialize() + return data[k] + end + setmetatable(data, m) +end + end -- of closure @@ -4190,6 +4206,7 @@ function statistics.show(reporter) local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0 return format("direct: %s, indirect: %s, total: %s", total-indirect, indirect, total) end) + collectgarbage("collect") register("current memory usage", statistics.memused) register("runtime",statistics.runtime) for i=1,#statusinfo do diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index c678597e1..60a44bd2a 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -1110,8 +1110,14 @@ local function serialize(root,name,_handle,_reduce,_noquotes,_hexify) else handle("t={") end - if root and next(root) then - do_serialize(root,name,"",0) + if root then + -- The dummy access will initialize a table that has a delayed initialization + -- using a metatable. + local dummy = root.whatever + -- Let's forget about empty tables. + if next(root) then + do_serialize(root,name,"",0) + end end handle("}") end @@ -4062,6 +4068,16 @@ function getmetatablekey(t,key,value) end +function storage.setinitializer(data,initialize) + local m = getmetatable(data) or { } + m.__index = function(data,k) + m.__index = nil -- so that we can access the entries during initializing + initialize() + return data[k] + end + setmetatable(data, m) +end + end -- of closure @@ -4190,6 +4206,7 @@ function statistics.show(reporter) local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0 return format("direct: %s, indirect: %s, total: %s", total-indirect, indirect, total) end) + collectgarbage("collect") register("current memory usage", statistics.memused) register("runtime",statistics.runtime) for i=1,#statusinfo do -- cgit v1.2.3