Skip to content

Commit 55be0cb

Browse files
AllenJBderickr
authored andcommitted
interactive-examples.js: Fix handling on newlines (multiple newlines collapsed)
1 parent c3b4e7f commit 55be0cb

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

js/interactive-examples.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,21 @@ class PHP {
3636
if (PHP.runPhp) {
3737
return PHP.runPhp;
3838
}
39+
let initializing = true;
3940

4041
const { ccall } = await phpBinary({
4142
print(data) {
42-
if (!data) {
43+
// The initial exec to get PHP version causes empty output we don't want
44+
if (initializing) {
4345
return;
4446
}
45-
46-
if (PHP.buffer.length) {
47-
PHP.buffer.push("\n");
48-
}
49-
PHP.buffer.push(data);
47+
PHP.buffer.push(data + "\n");
5048
},
5149
});
5250

5351
PHP.version = ccall("phpw_exec", "string", ["string"], ["phpversion();"]),
5452
console.log("PHP wasm %s loaded.", PHP.version);
53+
initializing = false;
5554
PHP.runPhp = (code) => ccall("phpw_run", null, ["string"], ["?>" + code]);
5655
return PHP.runPhp;
5756
}

js/php-web-README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
These files are built by [emcripten](https://github.com/emscripten-core/emscripten)
2+
via https://github.com/derickr/php-wasm-builder

0 commit comments

Comments
 (0)