diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-09 08:27:57 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-09 08:27:57 +0900 |
| commit | 925f7f4a11341fb950f4f6cd6390187b780ba419 (patch) | |
| tree | 78d1e1717234675da5e9ce36b6d3408cef586085 /examples/compile-php-to-wasm/php-wasm.c | |
| parent | 61d6fdffb161c8b4130eb4982f021fbc0c77c445 (diff) | |
| download | php-waddiwasi-925f7f4a11341fb950f4f6cd6390187b780ba419.tar.gz php-waddiwasi-925f7f4a11341fb950f4f6cd6390187b780ba419.tar.zst php-waddiwasi-925f7f4a11341fb950f4f6cd6390187b780ba419.zip | |
feat: add examples/compile-php-to-wasm
Diffstat (limited to 'examples/compile-php-to-wasm/php-wasm.c')
| -rw-r--r-- | examples/compile-php-to-wasm/php-wasm.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/compile-php-to-wasm/php-wasm.c b/examples/compile-php-to-wasm/php-wasm.c new file mode 100644 index 0000000..9c71ca1 --- /dev/null +++ b/examples/compile-php-to-wasm/php-wasm.c @@ -0,0 +1,22 @@ +#include <stdio.h> +#include <emscripten.h> +#include <Zend/zend_execute.h> +#include <sapi/embed/php_embed.h> + +int EMSCRIPTEN_KEEPALIVE php_wasm_run(const char* code) { + zend_result result; + + int argc = 1; + char* argv[] = { "php.wasm", NULL }; + + PHP_EMBED_START_BLOCK(argc, argv); + + result = zend_eval_string_ex(code, NULL, "php.wasm code", 1); + + PHP_EMBED_END_BLOCK(); + + fflush(stdout); + fflush(stderr); + + return result == SUCCESS ? 0 : 1; +} |
