-
Notifications
You must be signed in to change notification settings - Fork 53
/
main.html
64 lines (59 loc) · 2.17 KB
/
main.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<html>
<meta charset="utf-8">
<head>
<script type='text/javascript'>
var Module = {
postRun: [
text_changed
],
print: (function() {
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);
if(text != "emsc")
document.getElementById("result").innerHTML += "<br>\n" + text;
};
})(),
printErr: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
if (0) { // XXX disabled for safety typeof dump == 'function') {
dump(text + '\n'); // fast, straight to the real console
} else {
console.error(text);
}
}
};
var xhr = new XMLHttpRequest();
xhr.open('GET', 'main.wasm', true);
xhr.responseType = 'arraybuffer';
xhr.overrideMimeType("application/javascript");
xhr.onload = function() {
Module.wasmBinary = xhr.response;
var script = document.createElement('script');
script.src = "main.js";
document.body.appendChild(script);
};
xhr.send(null);
var timer;
function text_changed() {
clearTimeout(timer);
input = document.getElementById("edit").value;
timer = setTimeout(function() {
document.getElementById("result").innerHTML = "";
Module.ccall("run_lua", 'number', ['string'], [input]);
},
750);
}
</script>
</head>
<body>
<div>
<textarea id="edit" style="width: 800px; height: 480px;" onkeyup="text_changed();">
function hello_lua()
print "Hello Lua!"
end
hello_lua()</textarea>
<div id="result" style="width: 800px; float: right"></div>
</div>
</body>
</html>