summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChrisK2 <spam@kalania.de>2014-05-23 13:14:17 +0200
committerChrisK2 <spam@kalania.de>2014-05-23 13:14:17 +0200
commitc6915d732510812098e6e6c5f4d3d7e28fe21429 (patch)
tree6acd08413e979b3d49fa320207e009b489dc3114
parentb69d57ebe87cb43ea29ce7b7146d63338b7ed3e7 (diff)
downloadmpv-c6915d732510812098e6e6c5f4d3d7e28fe21429.tar.bz2
mpv-c6915d732510812098e6e6c5f4d3d7e28fe21429.tar.xz
lua/osc: small overhaul
Small fixes for the OSC, seektooltip now enabled by default. Option-parser now moved to separate package, can be used from other scripts, see DOCS/man/en/lua.rst. OSC config file location moved to lua-settings/osc.conf
-rw-r--r--player/lua/options.lua105
1 files changed, 105 insertions, 0 deletions
diff --git a/player/lua/options.lua b/player/lua/options.lua
new file mode 100644
index 0000000000..382a9e4a4b
--- /dev/null
+++ b/player/lua/options.lua
@@ -0,0 +1,105 @@
+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
+ if val == "yes" then
+ val = true
+ elseif val == "no" then
+ val = false
+ else
+ msg.error("Error: Can't convert " .. val .. " to boolean!")
+ val = nil
+ end
+ elseif type(desttypeval) == "number" then
+ if not (tonumber(val) == nil) then
+ val = tonumber(val)
+ else
+ msg.error("Error: Can't convert " .. val .. " to number!")
+ val = nil
+ end
+ end
+ return val
+end
+
+
+function read_options(options, identifier)
+ msg.debug("reading options for " .. identifier)
+
+ if identifier == nil then
+ identifier = mp.get_script_name()
+ end
+
+ -- read config file
+ local conffilename = "lua-settings/" .. identifier .. ".conf"
+ local conffile = mp.find_config_file(conffilename)
+ local f = conffile and io.open(conffile,"r")
+ if f == nil then
+ -- config not found
+ msg.verbose(conffilename .. " not found.")
+ else
+ -- config exists, read values
+ local linecounter = 1
+ for line in f:lines() do
+ if string.find(line, "#") == 1 then
+
+ else
+ local eqpos = string.find(line, "=")
+ if eqpos == nil then
+
+ else
+ local key = string.sub(line, 1, eqpos-1)
+ local val = string.sub(line, eqpos+1)
+
+ -- match found values with defaults
+ if options[key] == nil then
+ msg.warn(conffilename..":"..linecounter..
+ " unknown key " .. key .. ", ignoring")
+ else
+ local convval = typeconv(options[key], val)
+ if convval == nil then
+ msg.error(conffilename..":"..linecounter..
+ " error converting value '" .. val ..
+ "' for key '" .. key .. "'")
+ else
+ options[key] = convval
+ end
+ end
+ end
+ end
+ linecounter = linecounter + 1
+ end
+ io.close(f)
+ end
+
+ --parse commandline options
+ for key, val in pairs(mp.get_property_native("options/lua-opts")) do
+ local prefix = identifier.."-"
+ if not (string.find(key, prefix, 1, true) == nil) then
+ key = string.sub(key, string.len(prefix)+1)
+
+ -- match found values with defaults
+ if options[key] == nil then
+ msg.warn("lua-opts: unknown key " .. key .. ", ignoring")
+ else
+ local convval = typeconv(options[key], val)
+ if convval == nil then
+ msg.error("lua-opts: error converting value '" .. val ..
+ "' for key '" .. key .. "'")
+ else
+ options[key] = convval
+ end
+ end
+ end
+ end
+
+end
+
+