wasmerio / wasmer-php

🐘🕸️ WebAssembly runtime for PHP
https://wasmerio.github.io/wasmer-php/wasm/
MIT License
1k stars 42 forks source link

Cannot address by function name #145

Open dochne opened 3 years ago

dochne commented 3 years ago

I'm having some trouble with trying to make a sensible interface to actually using this library, but I may just be missing something obvious (or, alternatively, have completely missed a key paradigm :P)

Looking at your example copy of your exports-function.php example, we see that although we have an exported function of "sum", it only ever gets referenced by $exports->offsetGet(0), not by Sum.

Compiling the most barebones addition rust program, I end up with something like this:

(module
  (type $t0 (func (param i32) (result i32)))
  (func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32)
    (i32.add
      (local.get $p0)
      (i32.const 1)))
  (memory $memory (export "memory") 16)
  (global $__data_end (export "__data_end") i32 (i32.const 1048576))
  (global $__heap_base (export "__heap_base") i32 (i32.const 1048576)))

The only way I can find to reference that function is like so: $addOne = (new Wasm\Extern($exports->offsetGet(1)))->asFunc();

There doesn't seem to be an getByName or similar.

I can iterate through the exports and filter it down to the exports that are only functions, but I haven't had any success at finding any method that will then translate that function to what it's name is.

Thank you!