summaryrefslogtreecommitdiff
path: root/src/types.rs
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2023-08-03 00:56:17 +0100
committerAlex Orlenko <zxteam@protonmail.com>2023-08-03 00:56:17 +0100
commitcd0c8a4584401a68dc1141fe3b654eb647be27d0 (patch)
tree8045cda444dfdec6c898f563ae14a146960ea7d3 /src/types.rs
parent4fff14a14467c5cd95f85d5e6980e808ab82cffd (diff)
downloadmlua-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.rs9
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))]