diff options
author | Hans Hagen <pragma@wxs.nl> | 2017-10-18 21:34:02 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2017-10-18 21:34:02 +0200 |
commit | 4a7fb336e5a59645520c05690efe98c9c7270d37 (patch) | |
tree | ce8da19ee47ff43c5f44fc720c25e218d89a8ece /tex/context/base/mkiv/util-sto.lua | |
parent | f34b1249e3ad9bcbe34323c6daf0ad3174190649 (diff) | |
download | context-4a7fb336e5a59645520c05690efe98c9c7270d37.tar.gz |
2017-10-18 21:22:00
Diffstat (limited to 'tex/context/base/mkiv/util-sto.lua')
-rw-r--r-- | tex/context/base/mkiv/util-sto.lua | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/tex/context/base/mkiv/util-sto.lua b/tex/context/base/mkiv/util-sto.lua index d21267d7a..bcd8c85a3 100644 --- a/tex/context/base/mkiv/util-sto.lua +++ b/tex/context/base/mkiv/util-sto.lua @@ -6,7 +6,7 @@ if not modules then modules = { } end modules ['util-sto'] = { license = "see context related readme files" } -local setmetatable, getmetatable, type = setmetatable, getmetatable, type +local setmetatable, getmetatable, rawset, type = setmetatable, getmetatable, rawset, type utilities = utilities or { } utilities.storage = utilities.storage or { } @@ -172,3 +172,75 @@ function table.getmetatablekey(t,key,value) local m = getmetatable(t) return m and m[key] end + +-- Problem: we have no __next (which is ok as it would probably slow down lua) so +-- we cannot loop over the keys. + +-- local parametersets = table.autokeys() +-- +-- parametersets.foo.bar = function(t,k) return "OEPS" end +-- parametersets.foo.foo = "SPEO" +-- parametersets.crap = { a = "a", b = table.autokey { function() return "b" end } } +-- +-- print(parametersets.foo.bar) +-- print(parametersets.foo.foo) +-- print(parametersets.crap.b) +-- print(parametersets.crap.b[1]) + +-- function table.autotables(t) +-- local t = t or { } +-- local m = getmetatable(t) +-- if not m then +-- m = { } +-- setmetatable(t,m) +-- end +-- m.__newindex = function(t,k,p) +-- local v = { } +-- local m = { +-- __index = function(t,k) +-- local v = p[k] +-- if type(v) == "function" then +-- return v(t,k) -- so we can have multiple arguments +-- else +-- return v +-- end +-- end, +-- __newindex = function(t,k,v) +-- p[k] = v +-- end, +-- __len = function(t) +-- return #p +-- end, +-- } +-- setmetatable(v,m) +-- rawset(t,k,v) +-- return v +-- end +-- m.__index = function(t,k) +-- local v = { } +-- t[k] = v -- calls newindex +-- return v +-- end +-- return t +-- end +-- +-- function table.autokeys(p) +-- local t = { } +-- setmetatable(t, { +-- __newindex = function(t,k,v) +-- p[k] = v +-- end, +-- __index = function(t,k) +-- local v = p[k] +-- if type(v) == "function" then +-- return v(t,k) -- so we can have multiple arguments +-- else +-- return v +-- end +-- end, +-- __len = function(t) +-- return #p +-- end, +-- }) +-- return t +-- end |