summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-11-08 14:20:16 +0200
committerMarius <mariausol@gmail.com>2012-11-08 14:20:16 +0200
commit049b3c22a9db6218bf934d77356cc2d397fe5078 (patch)
tree42a1e9652f7c7c327e539400cbaf1ab3bdf3244d /scripts
parent1d0171ce126552c90869eab4fe4f0679bf459ce6 (diff)
downloadcontext-049b3c22a9db6218bf934d77356cc2d397fe5078.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
-rw-r--r--scripts/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 100644
--- 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)