diff --git a/README.md b/README.md index 2d5969195..1524a2e91 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ phpw(string filePath): void ```javascript const STR = 'string'; ccall("phpw", null, [STR], ["public/index.php"]); -console.log(ccall("phpw_exec", STR, [STR], ["phpversion();"]); +console.log(ccall("phpw_exec", STR, [STR], ["phpversion();"])); ``` [More about how to call exposed functions](https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html?highlight=call#interacting-with-code-ccall-cwrap) diff --git a/demo/.gitignore b/demo/.gitignore new file mode 100644 index 000000000..ddb38e888 --- /dev/null +++ b/demo/.gitignore @@ -0,0 +1,3 @@ +dist/ +public/ +!public/index.html diff --git a/demo/public/index.html b/demo/public/index.html new file mode 100644 index 000000000..8f6a4a890 --- /dev/null +++ b/demo/public/index.html @@ -0,0 +1,24 @@ + + diff --git a/demo/src/index.php b/demo/src/index.php new file mode 100644 index 000000000..83f154933 --- /dev/null +++ b/demo/src/index.php @@ -0,0 +1,3 @@ + - import Module from "./build/php-web.mjs"; - - const NUM = "number"; - const STR = "string"; - let body = ""; - const show = () => { - window.document.body.innerHTML = body; - }; - let timeout = null; - - Module({ - onAbort(reason) { - console.error(`WASM aborted: ${reason}`); - }, - print(data) { - if (data) { - body += data; - clearTimeout(timeout); - timeout = setTimeout(() => show()); - } - }, - printErr(data) { - if (data) { - console.log("stderr: ", data); - } - }, - }).then(({ ccall, FS, IDBFS }) => { - ccall("pib_init"); - const phpVersion = ccall("pib_exec", STR, [STR], ["phpversion();"]); - console.log("php version", phpVersion); - ccall("pib_exec", STR, [STR], ["phpinfo();"]); - }); -