PHP code example of kingbes / wasm
1. Go to this page and download the library: Download kingbes/wasm library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kingbes / wasm example snippets
ingbes\Wasm\Module;
use Kingbes\Wasm\ValType;
use Kingbes\Wasm\NumType;
$mod = new Module();
// 创建函数 add(i32, i32) -> i32
$fn = $mod->newFn([
"name" => "add",
"params" => [ValType::I32, ValType::I32],
"results" => [ValType::I32],
]);
// 编写函数体(链式调用)
$fn->getLocal(0)
->getLocal(1)
->add(NumType::I32);
// 提交并编译输出
$mod->commit($fn);
$mod->compile("./add.wasm");