Skip to content

Commit

Permalink
Local copies of various globals
Browse files Browse the repository at this point in the history
Std Lua practice.
  • Loading branch information
josephwright committed Mar 6, 2018
1 parent 1bf0dc0 commit 821f938
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
33 changes: 20 additions & 13 deletions l3build-arguments.lua
Expand Up @@ -25,6 +25,13 @@ for those people who are interested.
local exit = os.exit
local stderr = io.stderr
local find = string.find
local gmatch = string.gmatch
local match = string.match
local sub = string.sub
local insert = table.insert
-- Parse command line options
option_list =
Expand Down Expand Up @@ -140,7 +147,7 @@ local function argparse()
result["target"] = "help"
if a then
-- No options are allowed in position 1, so filter those out
if not string.match(a, "^%-") then
if not match(a, "^%-") then
result["target"] = a
end
end
Expand All @@ -152,7 +159,7 @@ local function argparse()
local function remainder(num)
local names = { }
for i = num, #arg do
table.insert(names, arg[i])
insert(names, arg[i])
end
return names
end
Expand All @@ -172,22 +179,22 @@ local function argparse()
local optarg
local opts
-- Look for and option and get it into a variable
if string.match(a, "^%-") then
if string.match(a, "^%-%-") then
if match(a, "^%-") then
if match(a, "^%-%-") then
opts = long_options
local pos = string.find(a, "=", 1, true)
local pos = find(a, "=", 1, true)
if pos then
opt = string.sub(a, 3, pos - 1)
optarg = string.sub(a, pos + 1)
opt = sub(a, 3, pos - 1)
optarg = sub(a, pos + 1)
else
opt = string.sub(a, 3)
opt = sub(a, 3)
end
else
opts = short_options
opt = string.sub(a, 2, 2)
opt = sub(a, 2, 2)
-- Only set optarg if it is there
if #a > 2 then
optarg = string.sub(a, 3)
optarg = sub(a, 3)
end
end
-- Now check that the option is valid and sort out the argument
Expand All @@ -197,7 +204,7 @@ local function argparse()
-- Tidy up arguments
if option_list[optname]["type"] == "boolean" then
if optarg then
local opt = "-" .. (string.match(a, "^%-%-") and "-" or "") .. opt
local opt = "-" .. (match(a, "^%-%-") and "-" or "") .. opt
stderr:write("Value not allowed for option " .. opt .."\n")
return {"help"}
end
Expand All @@ -221,8 +228,8 @@ local function argparse()
result[optname] = optarg
else
local opts = result[optname] or { }
for hit in string.gmatch(optarg, "([^,%s]+)") do
table.insert(opts, hit)
for hit in gmatch(optarg, "([^,%s]+)") do
insert(opts, hit)
end
result[optname] = opts
end
Expand Down
3 changes: 3 additions & 0 deletions l3build-aux.lua
Expand Up @@ -22,6 +22,9 @@ for those people who are interested.
--]]
local match = string.match
local pairs = pairs
local print = print
--
-- Auxiliary functions which are used by more than one main function
--
Expand Down
5 changes: 3 additions & 2 deletions l3build.lua
Expand Up @@ -32,6 +32,7 @@ local lfs = require("lfs")
local assert = assert
local ipairs = ipairs
local lookup = kpse.lookup
local next = next
local print = print
local select = select
Expand All @@ -41,9 +42,9 @@ local exit = os.exit
-- l3build setup and functions
kpse.set_program_name("kpsewhich")
build_kpse_path = string.match(kpse.lookup("l3build.lua"),"(.*[/])")
build_kpse_path = string.match(lookup("l3build.lua"),"(.*[/])")
local function build_require(s)
require( kpse.lookup("l3build-"..s..".lua", { path = build_kpse_path } ) )
require(lookup("l3build-"..s..".lua", { path = build_kpse_path } ) )
end
build_require("variables")
Expand Down

0 comments on commit 821f938

Please sign in to comment.