Stream: git-wasmtime

Topic: wasmtime / issue #12056 Seeking for a possible work aroun...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 20 2025 at 17:14):

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_table and call it with the current API?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 20 2025 at 17:42):

bjorn3 commented on issue #12056:

If __indirect_function_table is exported by a wasm module, I think you can use wasmtime_instance_export_get to get the table export, check that the kind is WASMTIME_EXTERN_TABLE and then use wasmtime_table_get to get an individual table item.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 20 2025 at 17:54):

leandro-benedet-garcia commented on issue #12056:

If __indirect_function_table is exported by a wasm module, I think you can use wasmtime_instance_export_get to get the table export, check that the kind is WASMTIME_EXTERN_TABLE and then use wasmtime_table_get to get an individual table item.

Is there any way to convert a wasm type into a wasmtime type without the need to start the process of creating a wasmtime_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_t with wasm_table_get but I had not realized that functions related to wasm_ref_t where 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.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 20 2025 at 18:11):

bjorn3 commented on issue #12056:

If you want to use wasm.h instead of wasmtime.h you should use wasm_module_exports and wasm_instance_exports together. 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 as wasm_extern_t that you can pass to wasm_extern_as_table (make sure to check that wasm_extern_kind returns a table first).

AFAIK there is no way to mix and match wasm.h and wasmtime.h.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 20 2025 at 18:33):

leandro-benedet-garcia commented on issue #12056:

If you want to use wasm.h instead of wasmtime.h you should use wasm_module_exports and wasm_instance_exports together. 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 as wasm_extern_t that you can pass to wasm_extern_as_table (make sure to check that wasm_extern_kind returns a table first).

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.

AFAIK there is no way to mix and match wasm.h and wasmtime.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?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 20 2025 at 19:25):

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_*_t and wasmtime_*_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 a wasm_instance_t.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 20 2025 at 20:51):

alexcrichton commented on issue #12056:

Using wasm.h exclusively you'd need to use wasm_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 using wasm.h for another engine, that's makes sense to want to keep using that, but I'll caution you that in general wasmtime.h-style APIs are what we recommend for the C API.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 20 2025 at 20:51):

alexcrichton added the wasmtime:c-api label to Issue #12056.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 20 2025 at 20:52):

leandro-benedet-garcia commented on issue #12056:

Using wasm.h exclusively you'd need to use wasm_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 using wasm.h for another engine, that's makes sense to want to keep using that, but I'll caution you that in general wasmtime.h-style APIs are what we recommend for the C API.

How difficult would be to implement it tho

view this post on Zulip Wasmtime GitHub notifications bot (Nov 20 2025 at 20:57):

alexcrichton commented on issue #12056:

It would be filling out this function which would involve changing [the representation of wasm_ref_t to internally contain a wasm_func_t instead of a Ref. This is a bit weird, but it's because we only support functions when creating wasm_ref_t


Last updated: Dec 06 2025 at 07:03 UTC