1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 15:22:09 +00:00

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.
This commit is contained in:
wm4 2014-02-26 20:58:17 +01:00
parent 25f086973f
commit 11ee72fe1b
2 changed files with 9 additions and 24 deletions

View File

@ -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

View File

@ -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