diff options
author | wm4 <wm4@nowhere> | 2014-02-26 20:58:17 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-02-26 21:03:36 +0100 |
commit | 11ee72fe1b4304ae16ff45c767c0d9e8f6e6f295 (patch) | |
tree | 956b691a2032397389649ac6074e3e5a5dee5e84 | |
parent | 25f086973ff267495586c776e79f91bc5ddc44fa (diff) |
lua: implement mp.get_opt() in Lua
Will be more expensive if used very often, but it's probably ok.
Reduce the dependency of lua.c on MPContext a bit further.
-rw-r--r-- | player/lua.c | 24 | ||||
-rw-r--r-- | player/lua/defaults.lua | 9 |
2 files changed, 9 insertions, 24 deletions
diff --git a/player/lua.c b/player/lua.c index 9e5e2c96a5..8b0a818ea5 100644 --- a/player/lua.c +++ b/player/lua.c @@ -823,29 +823,6 @@ static int script_format_time(lua_State *L) return 1; } -static int script_get_opt(lua_State *L) -{ - struct MPContext *mpctx = get_mpctx(L); - - mp_dispatch_lock(mpctx->dispatch); - - char **opts = mpctx->opts->lua_opts; - const char *name = luaL_checkstring(L, 1); - int r = 0; - - for (int n = 0; opts && opts[n] && opts[n + 1]; n++) { - if (strcmp(opts[n], name) == 0) { - lua_pushstring(L, opts[n + 1]); - r = 1; - break; - } - } - - mp_dispatch_unlock(mpctx->dispatch); - - return r; -} - struct fn_entry { const char *name; int (*fn)(lua_State *L); @@ -881,7 +858,6 @@ static struct fn_entry fn_list[] = { FN_ENTRY(input_set_section_mouse_area), FN_ENTRY(format_time), FN_ENTRY(enable_messages), - FN_ENTRY(get_opt), }; // On stack: mp table diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index 4f90b1d234..f8fe05ff82 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -4,6 +4,15 @@ function mp.get_script_name() return mp.script_name end +function mp.get_opt(key, def) + local opts = mp.get_property_native("options/lua-opts") + local val = opts[key] + if val == nil then + val = def + end + return val +end + local callbacks = {} -- each script has its own section, so that they don't conflict local default_section = "input_dispatch_" .. mp.script_name |