summaryrefslogtreecommitdiffstats
path: root/player/lua/options.lua
diff options
context:
space:
mode:
Diffstat (limited to 'player/lua/options.lua')
-rw-r--r--player/lua/options.lua39
1 files changed, 14 insertions, 25 deletions
diff --git a/player/lua/options.lua b/player/lua/options.lua
index 1ea0d7226c..4647677e3e 100644
--- a/player/lua/options.lua
+++ b/player/lua/options.lua
@@ -1,12 +1,5 @@
local msg = require 'mp.msg'
-local function val2str(val)
- if type(val) == "boolean" then
- if val then val = "yes" else val = "no" end
- end
- return val
-end
-
-- converts val to type of desttypeval
local function typeconv(desttypeval, val)
if type(desttypeval) == "boolean" then
@@ -15,14 +8,14 @@ local function typeconv(desttypeval, val)
elseif val == "no" then
val = false
else
- msg.error("Error: Can't convert " .. val .. " to boolean!")
+ msg.error("Error: Can't convert '" .. val .. "' to boolean!")
val = nil
end
elseif type(desttypeval) == "number" then
- if not (tonumber(val) == nil) then
+ if tonumber(val) ~= nil then
val = tonumber(val)
else
- msg.error("Error: Can't convert " .. val .. " to number!")
+ msg.error("Error: Can't convert '" .. val .. "' to number!")
val = nil
end
end
@@ -79,20 +72,16 @@ local function read_options(options, identifier, on_update)
if line:sub(#line) == "\r" then
line = line:sub(1, #line - 1)
end
- if string.find(line, "#") == 1 then
-
- else
+ if string.find(line, "#") ~= 1 then
local eqpos = string.find(line, "=")
- if eqpos == nil then
-
- else
+ if eqpos ~= nil then
local key = string.sub(line, 1, eqpos-1)
local val = string.sub(line, eqpos+1)
-- match found values with defaults
if option_types[key] == nil then
msg.warn(conffilename..":"..linecounter..
- " unknown key " .. key .. ", ignoring")
+ " unknown key '" .. key .. "', ignoring")
else
local convval = typeconv(option_types[key], val)
if convval == nil then
@@ -115,9 +104,9 @@ local function read_options(options, identifier, on_update)
-- command line options are always applied on top of these
local conf_and_default_opts = opt_table_copy(options)
- local function parse_opts(full, options)
+ local function parse_opts(full, opt)
for key, val in pairs(full) do
- if not (string.find(key, prefix, 1, true) == nil) then
+ if string.find(key, prefix, 1, true) == 1 then
key = string.sub(key, string.len(prefix)+1)
-- match found values with defaults
@@ -129,7 +118,7 @@ local function read_options(options, identifier, on_update)
msg.error("script-opts: error converting value '" .. val ..
"' for key '" .. key .. "'")
else
- options[key] = convval
+ opt[key] = convval
end
end
end
@@ -143,15 +132,15 @@ local function read_options(options, identifier, on_update)
if on_update then
local last_opts = opt_table_copy(options)
- mp.observe_property("options/script-opts", "native", function(name, val)
+ mp.observe_property("options/script-opts", "native", function(_, val)
local new_opts = opt_table_copy(conf_and_default_opts)
parse_opts(val, new_opts)
local changelist = {}
- for key, val in pairs(new_opts) do
- if not opt_equal(last_opts[key], val) then
+ for k, v in pairs(new_opts) do
+ if not opt_equal(last_opts[k], v) then
-- copy to user
- options[key] = opt_copy(val)
- changelist[key] = true
+ options[k] = opt_copy(v)
+ changelist[k] = true
end
end
last_opts = new_opts