edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
* [edbrowse-dev] [PATCH] rudimentary js_hello_quick.c
@ 2021-02-14 13:38 Kevin Carhart
  0 siblings, 0 replies; only message in thread
From: Kevin Carhart @ 2021-02-14 13:38 UTC (permalink / raw)
  To: Edbrowse-dev; +Cc: kevin

From 5713fcab3ee3c980f6365ee84a49f9c1213b2c89 Mon Sep 17 00:00:00 2001
From: Kevin Carhart <kevin@carhart.net>
Date: Sun, 14 Feb 2021 05:27:06 -0800
Subject: [PATCH] Basic proof-of-concept for embedding QuickJS

---
 src/js_hello_quick.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 src/js_hello_quick.c

diff --git a/src/js_hello_quick.c b/src/js_hello_quick.c
new file mode 100644
index 0000000..739bfbc
--- /dev/null
+++ b/src/js_hello_quick.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <string.h>
+#include "quickjs-libc.h"
+#include "quickjs.h"
+
+// gcc js_hello_quick.c -o js_hello_quick quickjs.c libregexp.c libunicode.c cutils.c -lm -ldl -lpthread
+
+int main(int argc, char **argv)
+{
+
+JSRuntime *rt;
+JSContext *ctx;
+int flags;
+rt = JS_NewRuntime();
+ctx = JS_NewContext(rt);
+JSValue val;
+const char *filename;
+
+char *x = "'hello world, the answer is ' + 6*7;";
+
+val = JS_Eval(ctx, x, strlen(x), filename, JS_EVAL_TYPE_GLOBAL);
+printf("%s\n",JS_AtomToCString(ctx,JS_ValueToAtom(ctx,val)));
+}
+
+
-- 
1.8.3.2



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-02-14 13:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-14 13:38 [edbrowse-dev] [PATCH] rudimentary js_hello_quick.c Kevin Carhart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).