leandro-benedet-garcia opened issue #12056:
Hello, I am doing something related to implementing function calls from a table, I did find this post which would do exactly what I need https://github.com/bytecodealliance/wasmtime/issues/2646#issuecomment-775491554. But seemingly the related api seems to have been removed, and I cannot find at all anything close to it from the documentation, and since the documentation of the C API is extremely hard to follow, I am opening this issue.
Basically, is there any work around that might allow me to get a function in
__indirect_function_tableand call it with the current API?
bjorn3 commented on issue #12056:
If
__indirect_function_tableis exported by a wasm module, I think you can usewasmtime_instance_export_getto get the table export, check that thekindisWASMTIME_EXTERN_TABLEand then usewasmtime_table_getto get an individual table item.
leandro-benedet-garcia commented on issue #12056:
If
__indirect_function_tableis exported by a wasm module, I think you can usewasmtime_instance_export_getto get the table export, check that thekindisWASMTIME_EXTERN_TABLEand then usewasmtime_table_getto get an individual table item.Is there any way to convert a
wasmtype into awasmtimetype without the need to start the process of creating awasmtime_instance_t?Basically I am trying to collaborate to a project that already uses the regular wasm functions and not wasmtime, basically I was able to get it working to get a
wasm_ref_twithwasm_table_getbut I had not realized that functions related towasm_ref_twhere not available and was wanting to know if it was possible to, somehow convert then into callable functions without starting the chain again just to call a function.
bjorn3 commented on issue #12056:
If you want to use
wasm.hinstead ofwasmtime.hyou should usewasm_module_exportsandwasm_instance_exportstogether. They both return a list of the same size. The former allows you to get the index of the export you need while the later allows you to get the right export aswasm_extern_tthat you can pass towasm_extern_as_table(make sure to check thatwasm_extern_kindreturns a table first).AFAIK there is no way to mix and match
wasm.handwasmtime.h.
leandro-benedet-garcia commented on issue #12056:
If you want to use
wasm.hinstead ofwasmtime.hyou should usewasm_module_exportsandwasm_instance_exportstogether. They both return a list of the same size. The former allows you to get the index of the export you need while the later allows you to get the right export aswasm_extern_tthat you can pass towasm_extern_as_table(make sure to check thatwasm_extern_kindreturns a table first).Yes, that part I already have, the problem is that I cannot seem to convert
wasm_ref_tto a callable function with wasm.h hence why I was hoping to at least figure out a way to convert.AFAIK there is no way to mix and match
wasm.handwasmtime.h.So basically if I have something already with wasm.h I will need to at least open the wasm file again just to be able to get the wasmtime types?
bjorn3 commented on issue #12056:
Yes, that part I already have, the problem is that I cannot seem to convert wasm_ref_t to a callable function with wasm.h hence why I was hoping to at least figure out a way to convert.
That would be
wasm_ref_as_func, but Wasmtime doesn't implement it...So basically if I have something already with wasm.h I will need to at least open the wasm file again just to be able to get the wasmtime types?
If you want to use anything from wasmtime.h at all you pretty much have to rewrite everything to use wasmtime.h. There is no way to convert between
wasm_*_tandwasmtime_*_t, so even reopening the wasm file with the wasmtime.h api won't be all that useful as you can't use it to call a function of awasm_instance_t.
alexcrichton commented on issue #12056:
Using
wasm.hexclusively you'd need to usewasm_ref_as_func, yeah, and that's not implemented today. If you're interested though I think it would be implementable to do this so this is likely "just a PR away" from getting filled out. If you're already usingwasm.hfor another engine, that's makes sense to want to keep using that, but I'll caution you that in generalwasmtime.h-style APIs are what we recommend for the C API.
alexcrichton added the wasmtime:c-api label to Issue #12056.
leandro-benedet-garcia commented on issue #12056:
Using
wasm.hexclusively you'd need to usewasm_ref_as_func, yeah, and that's not implemented today. If you're interested though I think it would be implementable to do this so this is likely "just a PR away" from getting filled out. If you're already usingwasm.hfor another engine, that's makes sense to want to keep using that, but I'll caution you that in generalwasmtime.h-style APIs are what we recommend for the C API.How difficult would be to implement it tho
alexcrichton commented on issue #12056:
It would be filling out this function which would involve changing [the representation of
wasm_ref_tto internally contain awasm_func_tinstead of aRef. This is a bit weird, but it's because we only support functions when creatingwasm_ref_t
Last updated: Dec 06 2025 at 07:03 UTC