History

scripting (lua/js): utils.getpid: make wrapper of pid property

We now have at least 3 scripting APIs which are trivial wrappers around properties: mp.get_mouse_pos, utils.getcwd, utils.getpid. After some discussion on IRC it was decided that it's easier for us to maintain them as trivial wrappers than to deprecate them and inflict pain on users and script authors, so currently no plan to deprecate.

Avi Halachmi (:avih) committed 5 years ago

Commit 02fbdf81 parent f3b2ea94 files · +5 −16Browse files

Unified · Split

4 files
  1. player/javascript.c +0 −8
  2. player/javascript/defaults.js +1 −0
  3. player/lua.c +0 −8
  4. player/lua/defaults.lua +4 −0
player/javascript.c+0−8
@@ -40,7 +40,6 @@ · 39 unmodified lines
4040 #include "misc/bstr.h"
4141 #include "osdep/timer.h"
4242 #include "osdep/threads.h"
43−#include "osdep/getpid.h"
4443 #include "stream/stream.h"
4544 #include "sub/osd.h"
4645 #include "core.h"
@@ -925,12 +924,6 @@ static void script_get_user_path(js_State *J, void *af) · 878 unmodified lines
925924 js_pushstring(J, mp_get_user_path(af, jctx(J)->mpctx->global, path));
926925 }
927926
928−// args: none
929−static void script_getpid(js_State *J)
930−{
931− js_pushnumber(J, mp_getpid());
932−}
933−
934927 // args: prefixed file name, data (c-str)
935928 static void script_write_file(js_State *J, void *af)
936929 {
@@ -1183,7 +1176,6 @@ static const struct fn_entry utils_fns[] = { · 246 unmodified lines
11831176 FN_ENTRY(split_path, 1),
11841177 AF_ENTRY(join_path, 2),
11851178 AF_ENTRY(get_user_path, 1),
1186− FN_ENTRY(getpid, 0),
11871179 FN_ENTRY(get_env_list, 0),
11881180
11891181 FN_ENTRY(read_file, 2),
player/javascript/defaults.js+1−0
@@ -663,6 +663,7 @@ mp.get_script_file = function() { return mp.script_file }; · 662 unmodified lines
663663 mp.get_script_directory = function() { return mp.script_path };
664664 mp.get_time = function() { return mp.get_time_ms() / 1000 };
665665 mp.utils.getcwd = function() { return mp.get_property("working-directory") };
666+mp.utils.getpid = function() { return mp.get_property_number("pid") }
666667 mp.get_mouse_pos = function() { return mp.get_property_native("mouse-pos") };
667668 mp.dispatch_event = dispatch_event;
668669 mp.process_timers = process_timers;
player/lua.c+0−8
@@ -45,7 +45,6 @@ · 44 unmodified lines
4545 #include "osdep/subprocess.h"
4646 #include "osdep/timer.h"
4747 #include "osdep/threads.h"
48−#include "osdep/getpid.h"
4948 #include "stream/stream.h"
5049 #include "sub/osd.h"
5150 #include "core.h"
@@ -1146,12 +1145,6 @@ static int script_join_path(lua_State *L) · 1094 unmodified lines
11461145 return 1;
11471146 }
11481147
1149−static int script_getpid(lua_State *L)
1150−{
1151− lua_pushnumber(L, mp_getpid());
1152− return 1;
1153−}
1154−
11551148 static int script_parse_json(lua_State *L, void *tmp)
11561149 {
11571150 mp_lua_optarg(L, 2);
@@ -1247,7 +1240,6 @@ static const struct fn_entry utils_fns[] = { · 89 unmodified lines
12471240 FN_ENTRY(file_info),
12481241 FN_ENTRY(split_path),
12491242 FN_ENTRY(join_path),
1250− FN_ENTRY(getpid),
12511243 AF_ENTRY(parse_json),
12521244 AF_ENTRY(format_json),
12531245 FN_ENTRY(get_env_list),
player/lua/defaults.lua+4−0
@@ -747,6 +747,10 @@ function mp_utils.getcwd() · 746 unmodified lines
747747 return mp.get_property("working-directory")
748748 end
749749
750+function mp_utils.getpid()
751+ return mp.get_property_number("pid")
752+end
753+
750754 function mp_utils.format_bytes_humanized(b)
751755 local d = {"Bytes", "KiB", "MiB", "GiB", "TiB", "PiB"}
752756 local i = 1

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t