summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2012-11-08 12:14:00 +0100
committerHans Hagen <pragma@wxs.nl>2012-11-08 12:14:00 +0100
commit45a97c1060f2edcb0556e36950b2bc0f549af0ae (patch)
tree4b6169eca4bd06fa70b4631c9afb481140b2f33b /scripts
parent7322c8238e527f50b0cd50b35b231b2734a869ba (diff)
downloadcontext-45a97c1060f2edcb0556e36950b2bc0f549af0ae.tar.gz
beta 2012.11.08 12:14
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtxrun.lua39
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua39
-rwxr-xr-xscripts/context/stubs/unix/mtxrun39
3 files changed, 96 insertions, 21 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index 96b153adf..114d2ef0c 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -4771,18 +4771,43 @@ local setmetatable, getmetatable, tonumber, tostring = setmetatable, getmetatabl
local type, next, rawset, tonumber, loadstring = type, next, rawset, tonumber, loadstring
local lpegmatch, P, Cs = lpeg.match, lpeg.P, lpeg.Cs
-function tables.definetable(target) -- defines undefined tables
- local composed, t, n = nil, { }, 0
- for name in gmatch(target,"([^%.]+)") do
- n = n + 1
+-- function tables.definetable(target) -- defines undefined tables
+-- local composed, t, n = nil, { }, 0
+-- for name in gmatch(target,"([^%.]+)") do
+-- n = n + 1
+-- if composed then
+-- composed = composed .. "." .. name
+-- else
+-- composed = name
+-- end
+-- t[n] = format("%s = %s or { }",composed,composed)
+-- end
+-- return concat(t,"\n")
+-- end
+
+local splitter = lpeg.tsplitat(".")
+
+function tables.definetable(target,nofirst,nolast) -- defines undefined tables
+ local composed, shortcut, t = nil, nil, { }
+ local snippets = lpegmatch(splitter,target)
+ for i=1,#snippets - (nolast and 1 or 0) do
+ local name = snippets[i]
if composed then
- composed = composed .. "." .. name
+ composed = shortcut .. "." .. name
+ shortcut = shortcut .. "_" .. name
+ t[#t+1] = format("local %s = %s if not %s then %s = { } %s = %s end",shortcut,composed,shortcut,shortcut,composed,shortcut)
else
composed = name
+ shortcut = name
+ if not nofirst then
+ t[#t+1] = format("%s = %s or { }",composed,composed)
+ end
end
- t[n] = format("%s = %s or { }",composed,composed)
end
- return concat(t,"\n")
+ if nolast then
+ composed = shortcut .. "." .. snippets[#snippets]
+ end
+ return concat(t,"\n"), composed
end
function tables.accesstable(target,root)
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index 96b153adf..114d2ef0c 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -4771,18 +4771,43 @@ local setmetatable, getmetatable, tonumber, tostring = setmetatable, getmetatabl
local type, next, rawset, tonumber, loadstring = type, next, rawset, tonumber, loadstring
local lpegmatch, P, Cs = lpeg.match, lpeg.P, lpeg.Cs
-function tables.definetable(target) -- defines undefined tables
- local composed, t, n = nil, { }, 0
- for name in gmatch(target,"([^%.]+)") do
- n = n + 1
+-- function tables.definetable(target) -- defines undefined tables
+-- local composed, t, n = nil, { }, 0
+-- for name in gmatch(target,"([^%.]+)") do
+-- n = n + 1
+-- if composed then
+-- composed = composed .. "." .. name
+-- else
+-- composed = name
+-- end
+-- t[n] = format("%s = %s or { }",composed,composed)
+-- end
+-- return concat(t,"\n")
+-- end
+
+local splitter = lpeg.tsplitat(".")
+
+function tables.definetable(target,nofirst,nolast) -- defines undefined tables
+ local composed, shortcut, t = nil, nil, { }
+ local snippets = lpegmatch(splitter,target)
+ for i=1,#snippets - (nolast and 1 or 0) do
+ local name = snippets[i]
if composed then
- composed = composed .. "." .. name
+ composed = shortcut .. "." .. name
+ shortcut = shortcut .. "_" .. name
+ t[#t+1] = format("local %s = %s if not %s then %s = { } %s = %s end",shortcut,composed,shortcut,shortcut,composed,shortcut)
else
composed = name
+ shortcut = name
+ if not nofirst then
+ t[#t+1] = format("%s = %s or { }",composed,composed)
+ end
end
- t[n] = format("%s = %s or { }",composed,composed)
end
- return concat(t,"\n")
+ if nolast then
+ composed = shortcut .. "." .. snippets[#snippets]
+ end
+ return concat(t,"\n"), composed
end
function tables.accesstable(target,root)
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index 96b153adf..114d2ef0c 100755
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -4771,18 +4771,43 @@ local setmetatable, getmetatable, tonumber, tostring = setmetatable, getmetatabl
local type, next, rawset, tonumber, loadstring = type, next, rawset, tonumber, loadstring
local lpegmatch, P, Cs = lpeg.match, lpeg.P, lpeg.Cs
-function tables.definetable(target) -- defines undefined tables
- local composed, t, n = nil, { }, 0
- for name in gmatch(target,"([^%.]+)") do
- n = n + 1
+-- function tables.definetable(target) -- defines undefined tables
+-- local composed, t, n = nil, { }, 0
+-- for name in gmatch(target,"([^%.]+)") do
+-- n = n + 1
+-- if composed then
+-- composed = composed .. "." .. name
+-- else
+-- composed = name
+-- end
+-- t[n] = format("%s = %s or { }",composed,composed)
+-- end
+-- return concat(t,"\n")
+-- end
+
+local splitter = lpeg.tsplitat(".")
+
+function tables.definetable(target,nofirst,nolast) -- defines undefined tables
+ local composed, shortcut, t = nil, nil, { }
+ local snippets = lpegmatch(splitter,target)
+ for i=1,#snippets - (nolast and 1 or 0) do
+ local name = snippets[i]
if composed then
- composed = composed .. "." .. name
+ composed = shortcut .. "." .. name
+ shortcut = shortcut .. "_" .. name
+ t[#t+1] = format("local %s = %s if not %s then %s = { } %s = %s end",shortcut,composed,shortcut,shortcut,composed,shortcut)
else
composed = name
+ shortcut = name
+ if not nofirst then
+ t[#t+1] = format("%s = %s or { }",composed,composed)
+ end
end
- t[n] = format("%s = %s or { }",composed,composed)
end
- return concat(t,"\n")
+ if nolast then
+ composed = shortcut .. "." .. snippets[#snippets]
+ end
+ return concat(t,"\n"), composed
end
function tables.accesstable(target,root)