summaryrefslogtreecommitdiffstats
path: root/player/lua.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-02-17 00:19:30 +0100
committerwm4 <wm4@nowhere>2014-02-17 02:52:58 +0100
commit5fd661b50ea60f32e73249d14b0c118dc1ac5dc6 (patch)
tree160e58ff00eb999d677c9e1596d9f8d5846b916e /player/lua.c
parent1fa8e2b60203643019a11a84ac23d7a95ae714d1 (diff)
downloadmpv-5fd661b50ea60f32e73249d14b0c118dc1ac5dc6.tar.bz2
mpv-5fd661b50ea60f32e73249d14b0c118dc1ac5dc6.tar.xz
lua: allow giving fallback values in get_property() calls
E.g. ``mp.get_property("foo", "value")`` will return ``value`` if the property can't be read.
Diffstat (limited to 'player/lua.c')
-rw-r--r--player/lua.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/player/lua.c b/player/lua.c
index c7f43e0870..576a2395d6 100644
--- a/player/lua.c
+++ b/player/lua.c
@@ -505,6 +505,8 @@ static int script_get_property(lua_State *L)
const char *name = luaL_checkstring(L, 1);
int type = lua_tointeger(L, lua_upvalueindex(1))
? MPV_FORMAT_OSD_STRING : MPV_FORMAT_STRING;
+ char *def_fallback = type == MPV_FORMAT_OSD_STRING ? "" : NULL;
+ char *def = (char *)luaL_optstring(L, 2, def_fallback);
char *result = NULL;
int err = mpv_get_property(ctx->client, name, type, &result);
@@ -513,9 +515,10 @@ static int script_get_property(lua_State *L)
talloc_free(result);
return 1;
}
- if (type == MPV_FORMAT_OSD_STRING) {
- lua_pushstring(L, "");
+ if (def) {
+ lua_pushstring(L, def);
lua_pushstring(L, mpv_error_string(err));
+ return 2;
}
return check_error(L, err);
}