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.
Unified · Split
| @@ -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 | ||
| 929 | static 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) |
| 935 | static void script_write_file(js_State *J, void *af) | 928 | static 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), |
| @@ -663,6 +663,7 @@ mp.get_script_file = function() { return mp.script_file }; · 662 unmodified lines | |||
| 663 | mp.get_script_directory = function() { return mp.script_path }; | 663 | mp.get_script_directory = function() { return mp.script_path }; |
| 664 | mp.get_time = function() { return mp.get_time_ms() / 1000 }; | 664 | mp.get_time = function() { return mp.get_time_ms() / 1000 }; |
| 665 | mp.utils.getcwd = function() { return mp.get_property("working-directory") }; | 665 | mp.utils.getcwd = function() { return mp.get_property("working-directory") }; |
| 666 | mp.utils.getpid = function() { return mp.get_property_number("pid") } | ||
| 666 | mp.get_mouse_pos = function() { return mp.get_property_native("mouse-pos") }; | 667 | mp.get_mouse_pos = function() { return mp.get_property_native("mouse-pos") }; |
| 667 | mp.dispatch_event = dispatch_event; | 668 | mp.dispatch_event = dispatch_event; |
| 668 | mp.process_timers = process_timers; | 669 | mp.process_timers = process_timers; |
| @@ -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 | ||
| 1149 | static int script_getpid(lua_State *L) | ||
| 1150 | { | ||
| 1151 | lua_pushnumber(L, mp_getpid()); | ||
| 1152 | return 1; | ||
| 1153 | } | ||
| 1154 | |||
| 1155 | static int script_parse_json(lua_State *L, void *tmp) | 1148 | static 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), |
| @@ -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") |
| 748 | end | 748 | end |
| 749 | 749 | ||
| 750 | function mp_utils.getpid() | ||
| 751 | return mp.get_property_number("pid") | ||
| 752 | end | ||
| 753 | |||
| 750 | function mp_utils.format_bytes_humanized(b) | 754 | function 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 = 1 | 756 | local i = 1 |