PHP code example of kambo / webassembly

1. Go to this page and download the library: Download kambo/webassembly 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/ */

    

kambo / webassembly example snippets


$engine = new Kambo\WebAssembly\Engine();
$store = new Kambo\WebAssembly\Store($engine);

// Example WAT (WebAssembly Text) code
$wat = '(module
    (func $sum (param i32 i32) (result i32)
        local.get 0
        local.get 1
        i32.add)
    (export "sum" (func $sum)))';

$wasmBytes = WasmerFFI::watToWasm($wat);
$module = new Module($store, $wasmBytes);
$instance = new Instance($store, $module);

$args = Collection::from([10, 32], Value::KIND_I32);
$result = $instance->callFunction('sum', $args);
echo $result[0]->asI32(); // Outputs: 42