diff options
author | Peter Melnichenko <mpeterval@gmail.com> | 2016-06-29 12:56:51 +0300 |
---|---|---|
committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-06-29 12:56:51 +0300 |
commit | d8a64d6fb04ab9a78fec2ff1ea8a03bf2c156b4f (patch) | |
tree | 3b0faf547127f75332bd8091dddb30492ee40142 | |
parent | 505b9dbd5bd9f5c7ab33dc14e590279f601652fb (diff) | |
download | luacov-d8a64d6fb04ab9a78fec2ff1ea8a03bf2c156b4f.tar.gz |
Allow setting globals in config to set options
Switch to a common config format using assignments to globals. E.g.
return {statsfile = "foo"}
becomes
statsfile = "foo"
Old format (returning a table) is still supported but has lower priority
on conflicts.
-rw-r--r-- | src/luacov/runner.lua | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/luacov/runner.lua b/src/luacov/runner.lua index 160cc95..a7f5685 100644 --- a/src/luacov/runner.lua +++ b/src/luacov/runner.lua @@ -307,29 +307,30 @@ local function set_config(configuration) runner.tick = runner.tick or runner.configuration.tick end -local function die(error_msg) - io.stderr:write(("Error: %s\n"):format(error_msg)) - raw_os_exit(1) -end - local function load_config_file(name, is_default) - local ok, conf, error_msg = util.load_config(name, _G) + local conf = setmetatable({}, {__index = _G}) + + local ok, ret, error_msg = util.load_config(name, conf) if ok then - if type(conf) ~= "table" then - die("config is not a table") + if type(ret) == "table" then + for key, value in pairs(ret) do + if conf[key] == nil then + conf[key] = value + end + end end return conf end - local error_type = conf + local error_type = ret if error_type == "read" and is_default then return nil end - die(("couldn't %s config file %s: %s"):format(error_type, name, error_msg)) + io.stderr:write(("Error: couldn't %s config file %s: %s\n"):format(error_type, name, error_msg)) end local default_config_file = ".luacov" |