From 7fc4b935d045c84e89459e726ff54ae331e4c574 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Sun, 29 Oct 2017 16:50:11 +0100 Subject: 2017-10-29 15:50:00 --- tex/context/base/mkiv/util-sto.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tex/context/base/mkiv/util-sto.lua') diff --git a/tex/context/base/mkiv/util-sto.lua b/tex/context/base/mkiv/util-sto.lua index bcd8c85a3..5b6915eaf 100644 --- a/tex/context/base/mkiv/util-sto.lua +++ b/tex/context/base/mkiv/util-sto.lua @@ -158,6 +158,29 @@ function table.setmetatablecall(t,f) return t end +-- the manual is somewhat fuzzy about this but suggests that one can best +-- set all fields before assigning a metatable + +function table.setmetatableindices(t,f,n,c) + if type(t) ~= "table" then + f, t = t, { } + end + local m = getmetatable(t) + local i = f_index[f] or f + if m then + m.__index = i + m.__newindex = n + m.__call = c + else + setmetatable(t,{ + __index = i, + __newindex = n, + __call = c, + }) + end + return t +end + function table.setmetatablekey(t,key,value) local m = getmetatable(t) if not m then -- cgit v1.2.3