diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2023-08-03 00:56:17 +0100 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2023-08-03 00:56:17 +0100 |
commit | cd0c8a4584401a68dc1141fe3b654eb647be27d0 (patch) | |
tree | 8045cda444dfdec6c898f563ae14a146960ea7d3 /src/types.rs | |
parent | 4fff14a14467c5cd95f85d5e6980e808ab82cffd (diff) | |
download | mlua-cd0c8a4584401a68dc1141fe3b654eb647be27d0.zip |
Optimize async functionality:
Rewrite using the new `push_into_stack()`/`from_stack()` methods.
Also store thread state (pointer) in `Thread` struct to avoid getting it every time.
Async userdata methods still need to have arguments stored in ref thread as stack is empty on every poll().
Diffstat (limited to 'src/types.rs')
-rw-r--r-- | src/types.rs | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/types.rs b/src/types.rs index baf31dc..a2b38e9 100644 --- a/src/types.rs +++ b/src/types.rs @@ -10,16 +10,13 @@ use std::{fmt, mem, ptr}; use rustc_hash::FxHashMap; -#[cfg(feature = "async")] -use futures_util::future::LocalBoxFuture; - use crate::error::Result; #[cfg(not(feature = "luau"))] use crate::hook::Debug; use crate::lua::{ExtraData, Lua}; #[cfg(feature = "async")] -use crate::value::MultiValue; +use {crate::value::MultiValue, futures_util::future::LocalBoxFuture}; #[cfg(feature = "unstable")] use {crate::lua::LuaInner, std::marker::PhantomData}; @@ -47,13 +44,13 @@ pub(crate) type CallbackUpvalue = Upvalue<Callback<'static, 'static>>; #[cfg(feature = "async")] pub(crate) type AsyncCallback<'lua, 'a> = - Box<dyn Fn(&'lua Lua, MultiValue<'lua>) -> LocalBoxFuture<'lua, Result<MultiValue<'lua>>> + 'a>; + Box<dyn Fn(&'lua Lua, MultiValue<'lua>) -> LocalBoxFuture<'lua, Result<c_int>> + 'a>; #[cfg(feature = "async")] pub(crate) type AsyncCallbackUpvalue = Upvalue<AsyncCallback<'static, 'static>>; #[cfg(feature = "async")] -pub(crate) type AsyncPollUpvalue = Upvalue<LocalBoxFuture<'static, Result<MultiValue<'static>>>>; +pub(crate) type AsyncPollUpvalue = Upvalue<LocalBoxFuture<'static, Result<c_int>>>; /// Type to set next Luau VM action after executing interrupt function. #[cfg(any(feature = "luau", doc))] |