From 75d3267b43093161f94db5199bd36f14c06b7457 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 17 Feb 2014 02:33:47 +0100 Subject: client API: add a client message event This comes with a "script_message" input command, which sends these messages. Used by the following commits. --- player/client.c | 1 + player/command.c | 16 ++++++++++++++++ player/lua.c | 13 +++++++++++++ 3 files changed, 30 insertions(+) (limited to 'player') diff --git a/player/client.c b/player/client.c index 937d5bad84..79f8f91324 100644 --- a/player/client.c +++ b/player/client.c @@ -841,6 +841,7 @@ static const char *event_table[] = { [MPV_EVENT_UNPAUSE] = "unpause", [MPV_EVENT_TICK] = "tick", [MPV_EVENT_SCRIPT_INPUT_DISPATCH] = "script-input-dispatch", + [MPV_EVENT_CLIENT_MESSAGE] = "client-message", }; const char *mpv_event_name(mpv_event_id event) diff --git a/player/command.c b/player/command.c index 71b0fa1e60..2831f710c1 100644 --- a/player/command.c +++ b/player/command.c @@ -3200,6 +3200,22 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) break; } + case MP_CMD_SCRIPT_MESSAGE: { + mpv_event_client_message *event = talloc_ptrtype(NULL, event); + *event = (mpv_event_client_message){0}; + for (int n = 1; n < cmd->nargs; n++) { + MP_TARRAY_APPEND(event, event->args, event->num_args, + cmd->args[n].v.s); + } + if (mp_client_send_event(mpctx, cmd->args[0].v.s, + MPV_EVENT_CLIENT_MESSAGE, event) < 0) + { + MP_VERBOSE(mpctx, "Can't find script '%s' for %s.\n", + cmd->args[0].v.s, cmd->name); + } + break; + } + #if HAVE_SYS_MMAN_H case MP_CMD_OVERLAY_ADD: overlay_add(mpctx, diff --git a/player/lua.c b/player/lua.c index 576a2395d6..dbe97cc278 100644 --- a/player/lua.c +++ b/player/lua.c @@ -421,9 +421,22 @@ static int script_wait_event(lua_State *L) lua_setfield(L, -2, "type"); // event break; } + case MPV_EVENT_CLIENT_MESSAGE: { + mpv_event_client_message *msg = event->data; + + lua_newtable(L); // event args + for (int n = 0; n < msg->num_args; n++) { + lua_pushinteger(L, n + 1); // event args N + lua_pushstring(L, msg->args[n]); // event args N val + lua_settable(L, -3); // event args + } + lua_setfield(L, -2, "args"); // event + break; + } default: ; } + // return event return 1; } -- cgit v1.2.3