Merge pull request #748 from LORgames/ssurtees/osTranslateCommands

os.translateCommands now supports multiple tokens
This commit is contained in:
Jason Perkins 2017-04-19 14:05:31 -04:00 committed by GitHub
commit 42bfc2244d
2 changed files with 24 additions and 8 deletions

View File

@ -535,15 +535,24 @@
end
local processOne = function(cmd)
local token = cmd:match("^{.+}")
if token then
token = token:sub(2, #token - 1):lower()
local args = cmd:sub(#token + 4)
local func = map[token] or os.commandTokens["_"][token]
if func then
cmd = func(args)
local i, j, prev
repeat
i, j = cmd:find("{.-}")
if i then
if i == prev then
break
end
local token = cmd:sub(i + 1, j - 1):lower()
local args = cmd:sub(j + 2)
local func = map[token] or os.commandTokens["_"][token]
if func then
cmd = cmd:sub(1, i -1) .. func(args)
end
prev = i
end
end
until i == nil
return cmd
end

View File

@ -177,6 +177,13 @@
test.isequal("test a b", os.translateCommands("{COPY} a b", "test"))
end
function suite.translateCommand_callsProcessor_multipleTokens()
os.commandTokens.test = {
copy = function(value) return "test " .. value end
}
test.isequal("test a b; test c d; test e f;", os.translateCommands("{COPY} a b; {COPY} c d; {COPY} e f;", "test"))
end
--
-- os.translateCommand() windows COPY tests
--