Commit 5b49d551 authored by Andrew Price's avatar Andrew Price
Browse files

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);
parent 4dbf0632
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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;
};

+8 −0
Original line number Diff line number Diff line
@@ -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:
+5 −0
Original line number Diff line number Diff line
@@ -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];