From 7849a36beb458985d1e8b15bd2706a6e084a5f33 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Fri, 4 Feb 2022 12:44:13 +0200 Subject: js: utils.get_user_path: make wrapper of expand-path When utils.get_user_path was added, the expand-path command didn't exist. Now it does, so remove the C code, make it a trivial wrapper. Keep this function for backward compat to not break scripts, but technically it's not required anymore. --- DOCS/man/javascript.rst | 6 +++--- player/javascript.c | 7 ------- player/javascript/defaults.js | 2 ++ 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/DOCS/man/javascript.rst b/DOCS/man/javascript.rst index a776cb32ea..99112db40b 100644 --- a/DOCS/man/javascript.rst +++ b/DOCS/man/javascript.rst @@ -215,9 +215,9 @@ Additional utilities ``undefined`` if the variable is not defined. ``mp.utils.get_user_path(path)`` - Expands (mpv) meta paths like ``~/x``, ``~~/y``, ``~~desktop/z`` etc. - ``read_file``, ``write_file``, ``append_file`` and ``require`` already use - this internally. + Trivial wrapper of the ``expand-path`` mpv command, returns a string. + ``read_file``, ``write_file``, ``append_file`` and ``require`` already + expand the path internally and accept mpv meta-paths like ``~~desktop/foo``. ``mp.utils.read_file(fname [,max])`` Returns the content of file ``fname`` as string. If ``max`` is provided and diff --git a/player/javascript.c b/player/javascript.c index 7f2dc0970b..453469de50 100644 --- a/player/javascript.c +++ b/player/javascript.c @@ -944,12 +944,6 @@ static void script_join_path(js_State *J, void *af) js_pushstring(J, mp_path_join(af, js_tostring(J, 1), js_tostring(J, 2))); } -static void script_get_user_path(js_State *J, void *af) -{ - const char *path = js_tostring(J, 1); - js_pushstring(J, mp_get_user_path(af, jctx(J)->mpctx->global, path)); -} - // args: is_append, prefixed file name, data (c-str) static void script__write_file(js_State *J, void *af) { @@ -1205,7 +1199,6 @@ static const struct fn_entry utils_fns[] = { FN_ENTRY(file_info, 1), FN_ENTRY(split_path, 1), AF_ENTRY(join_path, 2), - AF_ENTRY(get_user_path, 1), FN_ENTRY(get_env_list, 0), FN_ENTRY(read_file, 2), diff --git a/player/javascript/defaults.js b/player/javascript/defaults.js index bf83f42204..a938ffef65 100644 --- a/player/javascript/defaults.js +++ b/player/javascript/defaults.js @@ -674,6 +674,8 @@ mp.get_script_directory = function() { return mp.script_path }; mp.get_time = function() { return mp.get_time_ms() / 1000 }; mp.utils.getcwd = function() { return mp.get_property("working-directory") }; mp.utils.getpid = function() { return mp.get_property_number("pid") } +mp.utils.get_user_path = + function(p) { return mp.command_native(["expand-path", String(p)]) }; mp.get_mouse_pos = function() { return mp.get_property_native("mouse-pos") }; mp.utils.write_file = mp.utils._write_file.bind(null, false); mp.utils.append_file = mp.utils._write_file.bind(null, true); -- cgit v1.2.3