| @@ -503,6 +503,8 @@ error_out: · 502 unmodified lines |
| 503 | *********************************************************************/ | 503 | *********************************************************************/ |
| 504 | static void pushnode(js_State *J, mpv_node *node); | 504 | static void pushnode(js_State *J, mpv_node *node); |
| 505 | static void makenode(void *ta_ctx, mpv_node *dst, js_State *J, int idx); | 505 | static void makenode(void *ta_ctx, mpv_node *dst, js_State *J, int idx); |
| | 506 | static int jsL_checkint(js_State *J, int idx); |
| | 507 | static int64_t jsL_checkint64(js_State *J, int idx); |
| 506 | | 508 | |
| 507 | // Return the index in opts of stack[idx] (or of def if undefined), else throws. | 509 | // Return the index in opts of stack[idx] (or of def if undefined), else throws. |
| 508 | static int checkopt(js_State *J, int idx, const char *def, const char *opts[], | 510 | static int checkopt(js_State *J, int idx, const char *def, const char *opts[], |
| @@ -792,6 +794,21 @@ static void script_get_wakeup_pipe(js_State *J) · 283 unmodified lines |
| 792 | js_pushnumber(J, mpv_get_wakeup_pipe(jclient(J))); | 794 | js_pushnumber(J, mpv_get_wakeup_pipe(jclient(J))); |
| 793 | } | 795 | } |
| 794 | | 796 | |
| | 797 | // args: name (str), priority (int), id (uint) |
| | 798 | static void script__hook_add(js_State *J) |
| | 799 | { |
| | 800 | const char *name = js_tostring(J, 1); |
| | 801 | int pri = jsL_checkint(J, 2); |
| | 802 | uint64_t id = jsL_checkint64(J, 3); |
| | 803 | push_status(J, mpv_hook_add(jclient(J), id, name, pri)); |
| | 804 | } |
| | 805 | |
| | 806 | // args: id (uint) |
| | 807 | static void script__hook_continue(js_State *J) |
| | 808 | { |
| | 809 | push_status(J, mpv_hook_continue(jclient(J), jsL_checkint64(J, 1))); |
| | 810 | } |
| | 811 | |
| 795 | /********************************************************************** | 812 | /********************************************************************** |
| 796 | * mp.utils | 813 | * mp.utils |
| 797 | *********************************************************************/ | 814 | *********************************************************************/ |
| @@ -1103,6 +1120,22 @@ static bool same_as_int64(double d) · 305 unmodified lines |
| 1103 | return d >= INT64_MIN && d <= INT64_MAX && d == (int64_t)d; | 1120 | return d >= INT64_MIN && d <= INT64_MAX && d == (int64_t)d; |
| 1104 | } | 1121 | } |
| 1105 | | 1122 | |
| | 1123 | static int jsL_checkint(js_State *J, int idx) |
| | 1124 | { |
| | 1125 | double d = js_tonumber(J, idx); |
| | 1126 | if (!(d >= INT_MIN && d <= INT_MAX)) |
| | 1127 | js_error(J, "integer out of range at index %d", idx); |
| | 1128 | return d; |
| | 1129 | } |
| | 1130 | |
| | 1131 | static int64_t jsL_checkint64(js_State *J, int idx) |
| | 1132 | { |
| | 1133 | double d = js_tonumber(J, idx); |
| | 1134 | if (!(d >= INT64_MIN && d <= INT64_MAX)) |
| | 1135 | js_error(J, "integer out of range at index %d", idx); |
| | 1136 | return d; |
| | 1137 | } |
| | 1138 | |
| 1106 | // From the js stack value/array/object at index idx | 1139 | // From the js stack value/array/object at index idx |
| 1107 | static void makenode(void *ta_ctx, mpv_node *dst, js_State *J, int idx) | 1140 | static void makenode(void *ta_ctx, mpv_node *dst, js_State *J, int idx) |
| 1108 | { | 1141 | { |
| @@ -1243,6 +1276,13 @@ static void script_wait_event(js_State *J) · 134 unmodified lines |
| 1243 | js_setproperty(J, -2, "data"); // reply.data (value as observed type) | 1276 | js_setproperty(J, -2, "data"); // reply.data (value as observed type) |
| 1244 | break; | 1277 | break; |
| 1245 | } | 1278 | } |
| | 1279 | |
| | 1280 | case MPV_EVENT_HOOK: { |
| | 1281 | mpv_event_hook *hook = event->data; |
| | 1282 | js_pushnumber(J, hook->id); |
| | 1283 | js_setproperty(J, -2, "hook_id"); // reply.hook_id (is a number) |
| | 1284 | break; |
| | 1285 | } |
| 1246 | } // switch (event->event_id) | 1286 | } // switch (event->event_id) |
| 1247 | | 1287 | |
| 1248 | assert(top == js_gettop(J) - 1); | 1288 | assert(top == js_gettop(J) - 1); |
| @@ -1285,6 +1325,8 @@ static const struct fn_entry main_fns[] = { · 36 unmodified lines |
| 1285 | AF_ENTRY(format_time, 2), | 1325 | AF_ENTRY(format_time, 2), |
| 1286 | FN_ENTRY(enable_messages, 1), | 1326 | FN_ENTRY(enable_messages, 1), |
| 1287 | FN_ENTRY(get_wakeup_pipe, 0), | 1327 | FN_ENTRY(get_wakeup_pipe, 0), |
| | 1328 | FN_ENTRY(_hook_add, 3), |
| | 1329 | FN_ENTRY(_hook_continue, 1), |
| 1288 | FN_ENTRY(set_osd_ass, 3), | 1330 | FN_ENTRY(set_osd_ass, 3), |
| 1289 | FN_ENTRY(get_osd_size, 0), | 1331 | FN_ENTRY(get_osd_size, 0), |
| 1290 | FN_ENTRY(get_osd_margins, 0), | 1332 | FN_ENTRY(get_osd_margins, 0), |