-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use memory in version 3.0 #3113
Comments
Hi! Thanks for opening the issue. Seeing how other projects have upgraded Wasmer might help you a bit: swc-project/swc#5456 You can also post here your code and we can help you on migrating to 3.0. Meanwhile, here are the migration docs: https://github.com/wasmerio/wasmer/blob/master/docs/migration_to_3.0.0.md |
Basically, You will need to move from #[derive(wasmer::WasmerEnv, Clone)]
pub struct MyEnv {
#[wasmer(export)]
pub memory: wasmer::LazyInit<Memory>,
#[wasmer(export(name = "__alloc"))]
pub alloc_guest_memory: LazyInit<NativeFunc<u32, i32>>,
}
let my_env = MyEnv {
memory: Default::default(),
alloc_guest_memory: Default::default(),
};
let instance = Instance::new(&module, &imports); To: pub struct MyEnv {
pub memory: Option<Memory>,
pub alloc_guest_memory: Option<TypedFunction<i32, i32>>,
}
let mut my_env = MyEnv {
memory: None,
alloc_guest_memory: None,
};
let instance = Instance::new(&module, &imports);
my_env.memory = instance.exports.get_memory("memory");
my_env.alloc_guest_memory = instance.exports.get_typed_function("__alloc"); |
This is so great, just what I was looking for. Many thanks @syrusakbary ! |
WoW get it , this is even clearer. Thanks again 🙏🏻 I think this issue can be closed in a few days, so if anyone has a similar problem it will be easy to find a way @syrusakbary . |
I'll add my suggested code on the migration guide so it's easier to find! |
Summary
I am trying to use wasmer to run as AssemblyScript in rust, import functions is the main way to do this, but I'm stuck with memory and ptr at the moment 😭
We can use memory in version 1 and version 2 by set with
LazyInit
, but in new version,LazyInit
was deleted. So I'm confused about how to use it in import functions.How should I use it in the new version?
The text was updated successfully, but these errors were encountered: