diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2020-07-26 01:22:26 +0300 |
---|---|---|
committer | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2020-07-26 02:26:37 +0300 |
commit | b5368980a83a4308c710c2258a66623a7f63aabd (patch) | |
tree | 7b165d108fbebff1e24fcc42bba9ca3ff533d988 | |
parent | 9301cb78a89bd337d70df203644b221b9966c008 (diff) | |
download | mpv-b5368980a83a4308c710c2258a66623a7f63aabd.tar.bz2 mpv-b5368980a83a4308c710c2258a66623a7f63aabd.tar.xz |
js: add mp.utils.get_env_list() (match 0e7f53a5, 9301cb78)
-rw-r--r-- | DOCS/man/javascript.rst | 2 | ||||
-rw-r--r-- | player/javascript.c | 13 |
2 files changed, 15 insertions, 0 deletions
diff --git a/DOCS/man/javascript.rst b/DOCS/man/javascript.rst index 786d2e076b..53e5771b54 100644 --- a/DOCS/man/javascript.rst +++ b/DOCS/man/javascript.rst @@ -189,6 +189,8 @@ success, ``fn`` is called always a-sync, ``error`` is empty string on success. ``mp.utils.subprocess_detached(t)`` +``mp.utils.get_env_list()`` + ``mp.utils.getpid()`` (LE) ``mp.add_hook(type, priority, fn)`` diff --git a/player/javascript.c b/player/javascript.c index 6d41fd0ee3..e37fcd6c86 100644 --- a/player/javascript.c +++ b/player/javascript.c @@ -47,6 +47,8 @@ #include "client.h" #include "libmpv/client.h" +extern char **environ; + // List of builtin modules and their contents as strings. // All these are generated from player/javascript/*.js static const char *const builtin_files[][3] = { @@ -939,6 +941,16 @@ static void script_getenv(js_State *J) } } +// args: none +static void script_get_env_list(js_State *J) +{ + js_newarray(J); + for (int n = 0; environ && environ[n]; n++) { + js_pushstring(J, environ[n]); + js_setindex(J, -2, n); + } +} + // args: as-filename, content-string, returns the compiled result as a function static void script_compile_js(js_State *J) { @@ -1149,6 +1161,7 @@ static const struct fn_entry utils_fns[] = { AF_ENTRY(join_path, 2), AF_ENTRY(get_user_path, 1), FN_ENTRY(getpid, 0), + FN_ENTRY(get_env_list, 0), FN_ENTRY(read_file, 2), AF_ENTRY(write_file, 2), |