summaryrefslogtreecommitdiff
path: root/tex/context/base/util-tab.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2010-08-20 10:35:18 +0300
committerMarius <mariausol@gmail.com>2010-08-20 10:35:18 +0300
commit20da4ce347921be291c8804041bd8756e3bf1707 (patch)
treee079545741aeb84163b5888e77449c780e0233d6 /tex/context/base/util-tab.lua
parent7d7e0d3c8d778650105cfb479f31a2bb54d69d50 (diff)
downloadcontext-20da4ce347921be291c8804041bd8756e3bf1707.tar.gz
beta 2010.08.20 00:00
Diffstat (limited to 'tex/context/base/util-tab.lua')
-rw-r--r--tex/context/base/util-tab.lua50
1 files changed, 49 insertions, 1 deletions
diff --git a/tex/context/base/util-tab.lua b/tex/context/base/util-tab.lua
index c9a0923a5..323f3e2c7 100644
--- a/tex/context/base/util-tab.lua
+++ b/tex/context/base/util-tab.lua
@@ -10,7 +10,8 @@ utilities = utilities or {}
utilities.tables = utilities.tables or { }
local tables = utilities.tables
-local concat, format, gmatch = table.concat, string.format, string.gmatch
+local format, gmatch = string.format, string.gmatch
+local concat, insert, remove = table.concat, table.insert, table.remove
function tables.definetable(target) -- defines undefined tables
local composed, t = nil, { }
@@ -32,3 +33,50 @@ function tables.accesstable(target)
end
return t
end
+
+function table.removevalue(t,value) -- todo: n
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ remove(t,i)
+ -- remove all, so no: return
+ end
+ end
+ end
+end
+
+function table.insertbeforevalue(t,value,extra)
+ for i=1,#t do
+ if t[i] == extra then
+ remove(t,i)
+ end
+ end
+ for i=1,#t do
+ if t[i] == value then
+ insert(t,i,extra)
+ return
+ end
+ end
+ insert(t,1,extra)
+end
+
+function table.insertaftervalue(t,value,extra)
+ for i=1,#t do
+ if t[i] == extra then
+ remove(t,i)
+ end
+ end
+ for i=1,#t do
+ if t[i] == value then
+ insert(t,i+1,extra)
+ return
+ end
+ end
+ insert(t,#t+1,extra)
+end
+
+local _empty_table_ = { __index = function(t,k) return "" end }
+
+function table.setemptymetatable(t)
+ setmetatable(t,_empty_table_)
+end