diff options
author | sfan5 <sfan5@live.de> | 2017-12-17 01:25:23 +0100 |
---|---|---|
committer | Kevin Mitchell <kevmitch@gmail.com> | 2018-02-13 20:16:01 -0800 |
commit | 8f9785d128eef0eae656d32d664ae1a8bff0bb12 (patch) | |
tree | 61250cdc4cd0505492e245757450e1a672713640 /player | |
parent | f17246fec15963e7cc098cf7ba7263ad02877b99 (diff) | |
download | mpv-8f9785d128eef0eae656d32d664ae1a8bff0bb12.tar.bz2 mpv-8f9785d128eef0eae656d32d664ae1a8bff0bb12.tar.xz |
lua+js: Implement utils.getpid()
Usable for uniquely identifying mpv instances from
subprocesses, controlling mpv with AppleScript, ...
Adds a new mp_getpid() wrapper for cross-platform reasons.
Diffstat (limited to 'player')
-rw-r--r-- | player/javascript.c | 8 | ||||
-rw-r--r-- | player/lua.c | 8 |
2 files changed, 16 insertions, 0 deletions
diff --git a/player/javascript.c b/player/javascript.c index 3de900bdb1..9afc5f10da 100644 --- a/player/javascript.c +++ b/player/javascript.c @@ -40,6 +40,7 @@ #include "osdep/subprocess.h" #include "osdep/timer.h" #include "osdep/threads.h" +#include "osdep/getpid.h" #include "stream/stream.h" #include "sub/osd.h" #include "core.h" @@ -990,6 +991,12 @@ static void script_subprocess_detached(js_State *J, void *af) af_subprocess_common(J, 1, af); } +// args: none +static void script_getpid(js_State *J) +{ + js_pushnumber(J, mp_getpid()); +} + // args: prefixed file name, data (c-str) static void script_write_file(js_State *J, void *af) { @@ -1296,6 +1303,7 @@ static const struct fn_entry utils_fns[] = { AF_ENTRY(get_user_path, 1), AF_ENTRY(subprocess, 1), AF_ENTRY(subprocess_detached, 1), + FN_ENTRY(getpid, 0), FN_ENTRY(read_file, 2), AF_ENTRY(write_file, 2), diff --git a/player/lua.c b/player/lua.c index d928fdfa46..778830976c 100644 --- a/player/lua.c +++ b/player/lua.c @@ -44,6 +44,7 @@ #include "osdep/subprocess.h" #include "osdep/timer.h" #include "osdep/threads.h" +#include "osdep/getpid.h" #include "stream/stream.h" #include "sub/osd.h" #include "core.h" @@ -1252,6 +1253,12 @@ static int script_subprocess_detached(lua_State *L) return 1; } +static int script_getpid(lua_State *L) +{ + lua_pushnumber(L, mp_getpid()); + return 1; +} + static int script_parse_json(lua_State *L) { mp_lua_optarg(L, 2); @@ -1338,6 +1345,7 @@ static const struct fn_entry utils_fns[] = { FN_ENTRY(join_path), FN_ENTRY(subprocess), FN_ENTRY(subprocess_detached), + FN_ENTRY(getpid), FN_ENTRY(parse_json), FN_ENTRY(format_json), {0} |