[mw-devel] [Git][arthur/mw][master] js-duk: Implement input events
Andrew Price
welshbyte at sucs.org
Mon Nov 5 22:16:12 GMT 2018
Andrew Price pushed to branch master at Justin Mitchell / mw
Commits:
5b49d551 by Andrew Price at 2018-11-05T22:15:10+00:00
js-duk: Implement input events
Replaces bind(K_BIND_INPUT, ...).
function handler(ev)
{
switch (ev.type) {
...
case "input":
line = ev.data;
mw.print("You inputted: " + line);
mw.say("⭐ " + line + " ⭐");
return false; // Suppress normal processing
...
}
}
mw.onevent.push(handler);
- - - - -
3 changed files:
- src/client/event.h
- src/client/js-duk.c
- src/client/main.c
Changes:
=====================================
src/client/event.h
=====================================
--- a/src/client/event.h
+++ b/src/client/event.h
@@ -7,6 +7,7 @@ typedef enum {
MWEV_TYPE_NONE = 0,
MWEV_TYPE_MSG,
MWEV_TYPE_ONOFF,
+ MWEV_TYPE_INPUT,
} mwev_type_t;
struct mwevent {
@@ -14,6 +15,7 @@ struct mwevent {
union {
ipc_message_t *msg; /* MWEV_TYPE_MSG */
ipc_message_t *onoff; /* MWEV_TYPE_ONOFF */
+ const char *input; /* MWEV_TYPE_INPUT */
} ev_data;
};
=====================================
src/client/js-duk.c
=====================================
--- a/src/client/js-duk.c
+++ b/src/client/js-duk.c
@@ -893,6 +893,14 @@ static int js_push_event(struct mwevent *ev)
if (ret == 0)
duk_put_prop_string(ctx, idx, "data");
break;
+ case MWEV_TYPE_INPUT:
+ duk_require_stack(ctx, 2);
+ duk_push_string(ctx, "input");
+ duk_put_prop_string(ctx, idx, "type");
+ duk_push_string(ctx, ev->ev_data.input);
+ duk_put_prop_string(ctx, idx, "data");
+ ret = 0;
+ break;
case MWEV_TYPE_NONE:
/* Fall through */
default:
=====================================
src/client/main.c
=====================================
--- a/src/client/main.c
+++ b/src/client/main.c
@@ -814,7 +814,12 @@ void accept_command(char *cmd)
DoScript(&cmd[1]);
}else {
char *event_name=NULL;
+ struct mwevent ev = {
+ .ev_type = MWEV_TYPE_INPUT,
+ .ev_data.input = cmd,
+ };
script_output=1;
+ js_handle_event(&ev);
while ((event_name = NextLink(eventin_list, event_name)) != NULL) {
if (is_js(event_name)) {
const char *argv[2];
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/5b49d5513ca7fe5bb0f00adcd08916afe37f5451
--
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/5b49d5513ca7fe5bb0f00adcd08916afe37f5451
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20181105/31b0ac10/attachment-0001.html>
More information about the mw-devel
mailing list