--- /dev/null
+#ifdef __EMSCRIPTEN__
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <emscripten/emscripten.h>
+
+int main() {
+ printf("hello, world!\ntell me something\n");
+ return 0;
+}
+
+void reverse(char* s) {
+ char* start = s;
+ char* end = s - 1+ strlen(s);
+ char tmp;
+ while(start < end) {
+ tmp = *start;
+ *start = *end;
+ *end = tmp;
+ start++;
+ end--;
+ }
+}
+
+EMSCRIPTEN_KEEPALIVE char* do_this(char* in) {
+ char* out = strdup(in);
+ reverse(out);
+ return out;
+}
+
+
+#endif
--- /dev/null
+<!doctype html>
+<html lang="en-us">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="manifest" href="manifest.json" />
+ <link rel="shortcut icon" type="image/jpg" href="icon.png"/>
+ <title>minmal example</title>
+ </head>
+ <body>
+ <div id="outzone"></div>
+ <form id="inform">
+ <input id="in" type="text" autocorrect="off" autocapitalize="off"></input>
+ </form>
+ <script type='text/javascript'>
+ var Module = {
+ print: (function() {
+ var element = document.getElementById('outzone');
+ if (element) element.textContent = '';
+ return (...args) => {
+ var text = args.join(' ');
+ console.log(text);
+ if (element) {
+ let printelt = document.createElement('div');
+ printelt.textContent += text + "\n";
+ element.appendChild(printelt);
+ }
+ };
+ })(),
+ };
+ document.getElementById("inform").addEventListener("submit", e => {
+ e.preventDefault();
+ let outzone = document.getElementById("outzone");
+ let inelt = document.createElement('div');
+ let input = e.target[0].value
+ inelt.textContent += "<- " + input + "\n"
+ outzone.appendChild(inelt);
+ let outelt = document.createElement('div');
+ let output = Module.ccall("do_this", 'string', ['string'], [input])
+ outelt.textContent += " -> " + output + "\n"
+ outzone.appendChild(outelt);
+ let prompt = document.createElement('div');
+ prompt.textContent = "tell me something else: ";
+ outzone.appendChild(prompt);
+ document.getElementById("in").value = "";
+ });
+
+ if('serviceWorker' in navigator) {
+ console.log('registering');
+ navigator.serviceWorker.register('./sw.js')
+ .then(() => { console.log('sw reg'); });
+ }
+ else {
+ console.log('no sw in nav');
+ }
+ </script>
+ {{{ SCRIPT }}}
+ </body>
+</html>