My WASM VM is part of a C++ class. The class loads the binary blob, instantiates the module and keeps a reference to the module instantiation around.
I couldn't figure out a good way to access the class's resources: let's say I have a host function that needs access to some internal state of the class to properly calculate a value. How would such a pattern look like?
Host functions only take the exec_env and the function's parameter as input values, which makes sense. There just doesn't seem to be a way to somehow attach or use custom data/classes.
thank you!
IIUC, you want to access some custom data through exec_env, in WAMR this is API to attach user data to it:
wasm_runtime_set_user_data
you can use this API to attach the pointer to your class instance after creating the exec_env, then in your native functions use wasm_runtime_get_user_data to get it back.
Jun Xu said:
IIUC, you want to access some custom data through exec_env, in WAMR this is API to attach user data to it:
wasm_runtime_set_user_data
you can use this API to attach the pointer to your class instance after creating the exec_env, then in your native functions use wasm_runtime_get_user_data to get it back.
Thank you!
Last updated: Apr 10 2025 at 15:03 UTC