-
struct MyService(String);
impl UserData for MyService {
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
// bind a async function here...
methods.add_async_method("my_async_call", |lua, this, _| async move {
// ...
});
}
}
let script = r#"
function handle(svc)
svc:my_async_call()
end
"#;
let lua= Lua::new();
lua.load(script).exec()?;
async fn foobar() {
let svc = lua.create_userdata(MyService(...))?;
let globals = lua.globals();
let handler = globals.get::<_, Function>("handle");
vm.scope(|scope| {
// QUESTION: Is there any way to call async in the scope???
handler.call_async(svc).await?
})?;
}
|
Beta Was this translation helpful? Give feedback.
Answered by
khvzak
Sep 30, 2024
Replies: 1 comment
-
Only if you use Generally to provide (safe and sound) async in scope mlua needs to define an executor interface and bind to tokio (for example) which is not something I'm planning yet. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jjeffcaii
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Only if you use
block_on
function to execute future.Generally to provide (safe and sound) async in scope mlua needs to define an executor interface and bind to tokio (for example) which is not something I'm planning yet.