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
40#include "misc/bstr.h"40#include "misc/bstr.h"
41#include "osdep/timer.h"41#include "osdep/timer.h"
42#include "osdep/threads.h"42#include "osdep/threads.h"
43#include "osdep/getpid.h"
44#include "stream/stream.h"43#include "stream/stream.h"
45#include "sub/osd.h"44#include "sub/osd.h"
46#include "core.h"45#include "core.h"
@@ -925,12 +924,6 @@ static void script_get_user_path(js_State *J, void *af) · 878 unmodified lines
925 js_pushstring(J, mp_get_user_path(af, jctx(J)->mpctx->global, path));924 js_pushstring(J, mp_get_user_path(af, jctx(J)->mpctx->global, path));
926}925}
927 926
928// args: none
929static void script_getpid(js_State *J)
930{
931 js_pushnumber(J, mp_getpid());
932}
933
934// args: prefixed file name, data (c-str)927// args: prefixed file name, data (c-str)
935static void script_write_file(js_State *J, void *af)928static void script_write_file(js_State *J, void *af)
936{929{
@@ -1183,7 +1176,6 @@ static const struct fn_entry utils_fns[] = { · 246 unmodified lines
1183 FN_ENTRY(split_path, 1),1176 FN_ENTRY(split_path, 1),
1184 AF_ENTRY(join_path, 2),1177 AF_ENTRY(join_path, 2),
1185 AF_ENTRY(get_user_path, 1),1178 AF_ENTRY(get_user_path, 1),
1186 FN_ENTRY(getpid, 0),
1187 FN_ENTRY(get_env_list, 0),1179 FN_ENTRY(get_env_list, 0),
1188 1180
1189 FN_ENTRY(read_file, 2),1181 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
663mp.get_script_directory = function() { return mp.script_path };663mp.get_script_directory = function() { return mp.script_path };
664mp.get_time = function() { return mp.get_time_ms() / 1000 };664mp.get_time = function() { return mp.get_time_ms() / 1000 };
665mp.utils.getcwd = function() { return mp.get_property("working-directory") };665mp.utils.getcwd = function() { return mp.get_property("working-directory") };
666mp.utils.getpid = function() { return mp.get_property_number("pid") }
666mp.get_mouse_pos = function() { return mp.get_property_native("mouse-pos") };667mp.get_mouse_pos = function() { return mp.get_property_native("mouse-pos") };
667mp.dispatch_event = dispatch_event;668mp.dispatch_event = dispatch_event;
668mp.process_timers = process_timers;669mp.process_timers = process_timers;
player/lua.c+0−8
@@ -45,7 +45,6 @@ · 44 unmodified lines
45#include "osdep/subprocess.h"45#include "osdep/subprocess.h"
46#include "osdep/timer.h"46#include "osdep/timer.h"
47#include "osdep/threads.h"47#include "osdep/threads.h"
48#include "osdep/getpid.h"
49#include "stream/stream.h"48#include "stream/stream.h"
50#include "sub/osd.h"49#include "sub/osd.h"
51#include "core.h"50#include "core.h"
@@ -1146,12 +1145,6 @@ static int script_join_path(lua_State *L) · 1094 unmodified lines
1146 return 1;1145 return 1;
1147}1146}
1148 1147
1149static int script_getpid(lua_State *L)
1150{
1151 lua_pushnumber(L, mp_getpid());
1152 return 1;
1153}
1154
1155static int script_parse_json(lua_State *L, void *tmp)1148static int script_parse_json(lua_State *L, void *tmp)
1156{1149{
1157 mp_lua_optarg(L, 2);1150 mp_lua_optarg(L, 2);
@@ -1247,7 +1240,6 @@ static const struct fn_entry utils_fns[] = { · 89 unmodified lines
1247 FN_ENTRY(file_info),1240 FN_ENTRY(file_info),
1248 FN_ENTRY(split_path),1241 FN_ENTRY(split_path),
1249 FN_ENTRY(join_path),1242 FN_ENTRY(join_path),
1250 FN_ENTRY(getpid),
1251 AF_ENTRY(parse_json),1243 AF_ENTRY(parse_json),
1252 AF_ENTRY(format_json),1244 AF_ENTRY(format_json),
1253 FN_ENTRY(get_env_list),1245 FN_ENTRY(get_env_list),
player/lua/defaults.lua+4−0
@@ -747,6 +747,10 @@ function mp_utils.getcwd() · 746 unmodified lines
747 return mp.get_property("working-directory")747 return mp.get_property("working-directory")
748end748end
749 749
750function mp_utils.getpid()
751 return mp.get_property_number("pid")
752end
753
750function mp_utils.format_bytes_humanized(b)754function mp_utils.format_bytes_humanized(b)
751 local d = {"Bytes", "KiB", "MiB", "GiB", "TiB", "PiB"}755 local d = {"Bytes", "KiB", "MiB", "GiB", "TiB", "PiB"}
752 local i = 1756 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