summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DOCS/man/en/lua.rst14
-rw-r--r--player/lua.c7
2 files changed, 13 insertions, 8 deletions
diff --git a/DOCS/man/en/lua.rst b/DOCS/man/en/lua.rst
index 54b05d9ea5..046f2fe3ff 100644
--- a/DOCS/man/en/lua.rst
+++ b/DOCS/man/en/lua.rst
@@ -63,22 +63,24 @@ The ``mp`` module is preloaded, although it can be loaded manually with
These two commands are equivalent, except that the first version breaks
if the filename contains spaces or certain special characters.
-``mp.get_property(name)``
+``mp.get_property(name [,def])``
Return the value of the given property as string. These are the same
properties as used in input.conf. See `Properties`_ for a list of
properties. The returned string is formatted similar to ``${=name}``
(see `Property Expansion`_).
- Returns the string on success, or ``nil, error`` on error.
+ Returns the string on success, or ``def, error`` on error. ``def`` is the
+ second parameter provided to the function, and is nil if it's missing.
-``mp.get_property_osd(name)``
+``mp.get_property_osd(name [,def])``
Similar to ``mp.get_property``, but return the property value formatted for
OSD. This is the same string as printed with ``${name}`` when used in
input.conf.
- Returns the string on success, or ``"", error`` on error.
- Unlike ``get_property()``, assigning the return value to a variable will
- always result in a string.
+ Returns the string on success, or ``def, error`` on error. ``def`` is the
+ second parameter provided to the function, and is an empty string if it's
+ missing. Unlike ``get_property()``, assigning the return value to a variable
+ will always result in a string.
``mp.set_property(name, value)``
Set the given property to the given value. See ``mp.get_property`` and
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);
}