Skip to content

Commit

Permalink
Update wasm stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed May 3, 2022
1 parent 9629bb0 commit de2360d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 100 deletions.
6 changes: 3 additions & 3 deletions wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
input.value = i.substr(4)

var event = document.createEvent('KeyboardEvent')
event.initKeyEvent('keydown', true, true, window, false, false, false, false, 13, 0)
event.initKeyboardEvent('keydown', true, true, window, false, false, false, false, 13, 0)
// Keep trying until everything is loaded and the event is actually handled
var t = setInterval(function() {
if (!input.dispatchEvent(event)) // Returns false when handled, not an error (loljs)
Expand All @@ -86,12 +86,12 @@

if (elem.className == 'permalink') {
var event = document.createEvent('KeyboardEvent')
event.initKeyEvent('keydown', true, true, window, false, false, false, false, 38, 0)
event.initKeyboardEvent('keydown', true, true, window, false, false, false, false, 38, 0)
input.dispatchEvent(event)
var cmd = input.value

var event = document.createEvent('KeyboardEvent')
event.initKeyEvent('keydown', true, true, window, false, false, false, false, 40, 0)
event.initKeyboardEvent('keydown', true, true, window, false, false, false, false, 40, 0)
input.dispatchEvent(event)

if (cmd === '')
Expand Down
11 changes: 10 additions & 1 deletion wasm/make
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#!/bin/sh
set -euC

cd ../ && GOOS=js GOARCH=wasm go build -ldflags="" -o wasm/main.wasm
tag=$(git tag | tail -n1)
commit_info=$(git log -n1 --format=' %h %cd' --date='format:%Y-%m-%d')

# TODO: this fails:
# Uncaught (in promise) TypeError: import object field 'wasi_snapshot_preview1' is not an Object

cd ../
export GOOS=js GOARCH=wasm
go build -ldflags="-w -s -X \"main.version=$tag$commit_info\"" -o wasm/main.wasm
4 changes: 2 additions & 2 deletions wasm/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Write stdout to terminal.
let outputBuf = '';
const decoder = new TextDecoder("utf-8");
global.fs.writeSync = (fd, buf) => {
globalThis.fs.writeSync = (fd, buf) => {
outputBuf += decoder.decode(buf);
const nl = outputBuf.lastIndexOf("\n");
if (nl != -1) {
Expand All @@ -20,7 +20,7 @@
window.readline = function(progname, output, input, cb) {
var hist = [], hist_index = 0, reading_stdin = false;

global.fs.read = (fd, buffer, offset, length, position, callback) => {
globalThis.fs.read = (fd, buffer, offset, length, position, callback) => {
reading_stdin = true;
output.innerText += 'reading from stdin...\n'
};
Expand Down
Loading

0 comments on commit de2360d

Please sign in to comment.