You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When migrating from version 0.9 I encountered the issue that when I try to call an async method of a Arc<Mutex<T>> of a type that implements UserData for example the following code returns an error.
implUserDataforSharedData{fnadd_methods<M: mlua::UserDataMethods<Self>>(methods:&mutM){
methods.add_async_method("some_async_method", |_,mut this,()| asyncmove{println!("Hello");
tokio::time::sleep(Duration::from_secs(5)).await;println!("from the other side!");Ok(())});}}#[tokio::main]asyncfnmain() -> Result<(), mlua::Error>{let lua = Lua::new();
lua.load(r#" function test(shared_data) shared_data:some_async_method() end "#,).exec()?;let shared_data = Arc::new(Mutex::new(SharedData::new()));let func: mlua::Function = lua.globals().get("test")?;
func.call_async::<()>(shared_data).await}
The error returned:
Error: CallbackError { traceback: "stack traceback:\n\t[C]: in local 'poll'\n\t[string \"?\"]:4: in method 'some_async_method'\n\t[string \"src/main.rs:40:9\"]:3: in function 'test'", cause: BadArgument { to: Some("SharedData.some_async_method"), pos: 1, name: Some("self"), cause: UserDataTypeMismatch } }
Is this intended behavior?
The text was updated successfully, but these errors were encountered:
This is not supported yet.
As a workaround you can change method to:
methods.add_async_function("some_async_method", |_,this:UserDataRef<Arc<Mutex<Self>>>| asyncmove{println!("Hello");
tokio::time::sleep(Duration::from_secs(1)).await;println!("from the other side!");Ok(())});
Or receiving AnyUserData and then trying to borrow Self or Arc<Mutex<Self>> to support all cases.
I'll try to fix this in next version, it's not trivial unfortunately.
When migrating from version 0.9 I encountered the issue that when I try to call an async method of a
Arc<Mutex<T>>
of a type that implementsUserData
for example the following code returns an error.The error returned:
Is this intended behavior?
The text was updated successfully, but these errors were encountered: