Commit 9c272029 authored by Andrew Price's avatar Andrew Price
Browse files

duktape: Implement beep()

parent de5bd188
Loading
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -177,6 +177,20 @@ static duk_ret_t js_wholist(duk_context *cx)
	return 1; /* Array is returned at top of stack */
}

static duk_ret_t js_beep(duk_context *cx)
{
	int i, beeps;

	beeps = duk_get_int_default(cx, -1, 1);
	if (beeps < 1 || beeps > 5) {
		beeps = 0;
		fprintf(stderr, "beep() will only do between 1 and 5 beeps\n");
	}
	for (i = 0; i < beeps; i++)
		write(STDOUT_FILENO, "\7", 1);
	return 0;
}

static duk_ret_t js_bind(duk_context *cx)
{
	const char *bind_name = NULL;
@@ -438,6 +452,7 @@ int setup_js(void)
	define_func("exec", js_mwexec, 1);
	define_func("say", js_say, 1);
	define_func("wholist", js_wholist, 0);
	define_func("beep", js_beep, 1);
	define_func("bind", js_bind, 3);
	define_func("unbind", js_unbind, 2);
	duk_pop(ctx);