-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform.pluto
43 lines (36 loc) · 1.31 KB
/
platform.pluto
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
platform = {}
function platform.watchinput(fn)
local handler = function()
js_invoke("get_input")
fn(io.contents("input"))
end
document.getElementById("input"):addEventListener("input", handler)
if tool.numeric then
document.getElementById("format"):addEventListener("input", handler)
end
js_invoke("get_input")
fn(io.contents("input"))
end
function platform.setoutput(data)
if tool.numeric then
-- Assuming we have an unsigned int here. Passing it on to Javascript will make it signed because WASM is 32-bit but using `tostring` produces the unsigned representation.
switch document.getElementById("format").value do
case "Decimal (Unsigned)": data = tostring(data) break
case "Hexadecimal (Unsigned)": data = string.format("%08X", data) break
end
end
document.getElementById("output").value = data
end
function platform.setoutputpng(data)
document.getElementById("output").src = "data:image/png;base64,"..(require"base64".encode(data))
end
function platform.watchoutput(fn)
document.getElementById("output"):removeAttribute("readonly")
document.getElementById("output"):addEventListener("input", function()
js_invoke("get_output")
fn(io.contents("output"))
end)
end
function platform.setinput(data)
document.getElementById("input").value = data
end