Skip to content

Commit ad314c4

Browse files
committed
fix(emscripten playground): better capture of console.log output
1 parent 9bd6e6b commit ad314c4

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ include/Ark/Constants.hpp
3030

3131
# WASM
3232
/public/node_modules
33-
/public/*.wasm.wasm
34-
/public/*.wasm.js
33+
/public/ArkEmscripten.*
3534
/public/package.json
3635
/public/package-lock.json
3736

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
- `APPEND_IN_PLACE_SYM` and `APPEND_IN_PLACE_SYM_INDEX` super instructions
6161
- `PUSH_RETURN_ADDRESS` instruction now replaces the VM auto push of IP/PP
6262
- remove the stack swapping by pushing arguments in the reverse order by which they are loaded
63+
- wasm export: we can now run ArkScript code on the web!
6364

6465
### Changed
6566
- instructions are on 4 bytes: 1 byte for the instruction, 1 byte of padding, 2 bytes for an immediate argument

public/index.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,29 @@
1313
</div>
1414

1515
<script>
16-
let output = "";
1716
log = console.log;
17+
var can_capture = false;
18+
1819
window.console.log = (message) => {
19-
output = message;
20+
log(message);
21+
if (can_capture)
22+
document.getElementById("output").value += message + "\n";
2023
};
2124

2225
var Module = {
2326
onRuntimeInitialized: function () {
2427
document.getElementById("run").addEventListener("click", () => {
28+
document.getElementById("output").value = "";
2529
const code = document.getElementById("code").value;
26-
console.log(code);
2730

2831
try {
32+
can_capture = true;
2933
Module.run(code);
30-
document.getElementById("output").innerText = output;
3134
} catch (e) {
32-
document.getElementById("output").innerText = e;
35+
document.getElementById("output").value = e;
3336
}
37+
38+
can_capture = false;
3439
});
3540
}
3641
};

src/arkscript/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ int main(int argc, char** argv)
209209
"sizeof(Ark::Value) = {}B\n"
210210
" sizeof(Value_t) = {}B\n"
211211
" sizeof(ValueType) = {}B\n"
212-
" sizeof(ProcType) = {}B\n"
213-
" sizeof(Ark::Closure) = {}B\n"
214-
" sizeof(Ark::UserType) = {}B\n"
212+
" sizeof(Ark::Procedure) = {}B\n"
213+
" sizeof(Ark::Closure) = {}B\n"
214+
" sizeof(Ark::UserType) = {}B\n"
215215
"\nVirtual Machine\n"
216216
"sizeof(Ark::VM) = {}B\n"
217217
" sizeof(Ark::State) = {}B\n"

0 commit comments

Comments
 (0)