forked from vvanders/wasm_lua
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
63 lines (56 loc) · 1.62 KB
/
index.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
<html>
<meta charset="utf-8">
<head>
<script src="main.js"></script>
<script>
var Module = undefined;
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);
}
// init wasm module
var ModuleConfig = {
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);
}
}
};
// initWasmModule function name configured in makefile
initWasmModule(ModuleConfig).then((aModule) => {
Module = aModule;
text_changed();
});
</script>
</head>
<body>
<div>
<textarea id="edit" style="width: 800px; height: 480px;" onkeyup="text_changed();">
function hello_lua()
print "Hello Lua!"
print(_VERSION)
alert("this alert is from lua")
end
hello_lua()
return "this is return value"</textarea>
<div id="result" style="width: 800px; float: right"></div>
</div>
</body>
</html>