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.
This commit is contained in:
sfan5 authored and Kevin Mitchell committed 2018-02-13 20:16:01 -08:00
1 parent f17246fec1
commit 8f9785d128
5 files changed
+51

No files matched your search

+8
View File
@@ -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),