[mw-devel] [Git][arthur/mw][master] duktape: Implement beep()

Andrew Price welshbyte at sucs.org
Mon Jul 10 22:26:47 BST 2017


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
9c272029 by Andrew Price at 2017-07-10T22:25:58+01:00
duktape: Implement beep()

- - - - -


1 changed file:

- src/client/js-duk.c


Changes:

=====================================
src/client/js-duk.c
=====================================
--- a/src/client/js-duk.c
+++ b/src/client/js-duk.c
@@ -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);



View it on GitLab: https://projects.sucs.org/arthur/mw/commit/9c2720294671d09a5f54e59f71e1f0a0291eebce

---
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/9c2720294671d09a5f54e59f71e1f0a0291eebce
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/20170710/02b9cdeb/attachment-0001.html>


More information about the mw-devel mailing list