How to get wasm export function name in C/C++?

Hi, I have been trying recently to run WASI-WASM in a C/C++ environment using the C-API provided by Wasmer, and I hope to use some of its internal export functions.

And I referred to the sample code related to WASI provided in the Wasmer documentation, and it can indeed run normally, and I can also obtain exports by wasm_instance_exports(instance, &exports);

I can only get the type of the exports by wasm_extern_kind(), But I want to call a specific function here. I look up all the api that wasmer provided but I just can't find one. So I have no idea how to get the function name.

here is part of the sample code:

// ...
own wasm_extern_vec_t exports;
wasm_instance_exports(instance, &exports);
for (int i = 0; i < exports.size; i++) {
    if (wasm_extern_kind([i]) == WASM_EXTERN_FUNC) {
        wasm_func_t *func = wasm_extern_as_func([i]);
        // I wonder how can I get the name of the `func`

How can I fix that?

I exactly got the same question, every time I need to try each export data to figure out the function that I want.

I already found a way to get the name.

First, you can get the export_types and the exports via wasm_module_exports(module, &export_types); and wasm_instance_exports(instance, &exports);.

Then, you can iterate this export_types or the exports. (The index order and total size of these two are the same.) You can get the wrapped wasm name via wasm_exporttype_name([i]);

After that, you can get the origin char pointer via And I think it'll be better to limit the size of the like this:

// you can use memcpy in `C`
std::string name_str = std::string(name->data, name->size);

Or it may be not the string that you want.

Now you get the name!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.