summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/conversion.rs10
-rw-r--r--src/error.rs2
-rw-r--r--src/function.rs2
-rw-r--r--src/lua.rs21
-rw-r--r--src/scope.rs2
-rw-r--r--src/thread.rs25
-rw-r--r--src/userdata_impl.rs1
-rw-r--r--src/util/mod.rs2
8 files changed, 29 insertions, 36 deletions
diff --git a/src/conversion.rs b/src/conversion.rs
index 98ba199..4679334 100644
--- a/src/conversion.rs
+++ b/src/conversion.rs
@@ -52,7 +52,7 @@ impl<'lua> FromLua<'lua> for String<'lua> {
lua.coerce_string(value)?
.ok_or_else(|| Error::FromLuaConversionError {
from: ty,
- to: "String",
+ to: "string",
message: Some("expected string or number".to_string()),
})
}
@@ -211,7 +211,7 @@ impl<'lua> FromLua<'lua> for OwnedAnyUserData {
}
}
-impl<'lua, T: 'static + MaybeSend + UserData> IntoLua<'lua> for T {
+impl<'lua, T: UserData + MaybeSend + 'static> IntoLua<'lua> for T {
#[inline]
fn into_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
Ok(Value::UserData(lua.create_userdata(self)?))
@@ -435,7 +435,7 @@ impl<'lua> FromLua<'lua> for BString {
lua.coerce_string(value)?
.ok_or_else(|| Error::FromLuaConversionError {
from: ty,
- to: "String",
+ to: "BString",
message: Some("expected string or number".to_string()),
})?
.as_bytes()
@@ -556,7 +556,7 @@ lua_convert_float!(f64);
impl<'lua, T> IntoLua<'lua> for &[T]
where
- T: Clone + IntoLua<'lua>,
+ T: IntoLua<'lua> + Clone,
{
#[inline]
fn into_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
@@ -599,7 +599,7 @@ where
let vec = table.sequence_values().collect::<Result<Vec<_>>>()?;
vec.try_into()
.map_err(|vec: Vec<T>| Error::FromLuaConversionError {
- from: "Table",
+ from: "table",
to: "Array",
message: Some(format!("expected table of length {}, got {}", N, vec.len())),
})
diff --git a/src/error.rs b/src/error.rs
index 88dce2a..647b505 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -64,7 +64,7 @@ pub enum Error {
/// called with a huge number of arguments, or a rust callback returns a huge number of return
/// values.
StackError,
- /// Too many arguments to `Function::bind`
+ /// Too many arguments to `Function::bind`.
BindError,
/// Bad argument received from Lua (usually when calling a function).
///
diff --git a/src/function.rs b/src/function.rs
index 0dac0e1..37ebc01 100644
--- a/src/function.rs
+++ b/src/function.rs
@@ -462,7 +462,7 @@ impl<'lua> Function<'lua> {
/// Requires `feature = "luau"`
///
/// [`Compiler::set_coverage_level`]: crate::chunk::Compiler::set_coverage_level
- #[cfg(any(feature = "luau", docsrs))]
+ #[cfg(any(feature = "luau", doc))]
#[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
pub fn coverage<F>(&self, mut func: F)
where
diff --git a/src/lua.rs b/src/lua.rs
index 5c5732c..0d356ba 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -96,6 +96,7 @@ pub(crate) struct ExtraData {
libs: StdLib,
mem_state: Option<NonNull<MemoryState>>,
+ // Auxiliary thread to store references
ref_thread: *mut ffi::lua_State,
ref_stack_size: c_int,
ref_stack_top: c_int,
@@ -697,8 +698,6 @@ impl Lua {
///
/// This function is useful when the `Lua` object is supposed to live for the remainder
/// of the program's life.
- /// In particular in asynchronous context this will allow to spawn Lua tasks to execute
- /// in background.
///
/// Dropping the returned reference will cause a memory leak. If this is not acceptable,
/// the reference should first be wrapped with the [`Lua::from_static`] function producing a `Lua`.
@@ -727,7 +726,7 @@ impl Lua {
where
A: FromLuaMulti<'lua>,
R: IntoLua<'lua>,
- F: 'static + MaybeSend + Fn(&'lua Lua, A) -> Result<R>,
+ F: Fn(&'lua Lua, A) -> Result<R> + MaybeSend + 'static,
{
let entrypoint_inner = |lua: &'lua Lua, func: F| {
let state = lua.state();
@@ -769,7 +768,7 @@ impl Lua {
pub unsafe fn entrypoint1<'lua, R, F>(self, func: F) -> Result<c_int>
where
R: IntoLua<'lua>,
- F: 'static + MaybeSend + Fn(&'lua Lua) -> Result<R>,
+ F: Fn(&'lua Lua) -> Result<R> + MaybeSend + 'static,
{
self.entrypoint(move |lua, _: ()| func(lua))
}
@@ -1130,7 +1129,7 @@ impl Lua {
/// a `Error::MemoryError` is generated instead.
/// Returns previous limit (zero means no limit).
///
- /// Does not work on module mode where Lua state is managed externally.
+ /// Does not work in module mode where Lua state is managed externally.
pub fn set_memory_limit(&self, limit: usize) -> Result<usize> {
unsafe {
match (*self.extra.get()).mem_state.map(|mut x| x.as_mut()) {
@@ -1533,7 +1532,7 @@ impl Lua {
where
A: FromLuaMulti<'lua>,
R: IntoLuaMulti<'lua>,
- F: 'static + MaybeSend + Fn(&'lua Lua, A) -> Result<R>,
+ F: Fn(&'lua Lua, A) -> Result<R> + MaybeSend + 'static,
{
self.create_callback(Box::new(move |lua, args| {
func(lua, A::from_lua_multi_args(args, 1, None, lua)?)?.into_lua_multi(lua)
@@ -1550,7 +1549,7 @@ impl Lua {
where
A: FromLuaMulti<'lua>,
R: IntoLuaMulti<'lua>,
- F: 'static + MaybeSend + FnMut(&'lua Lua, A) -> Result<R>,
+ F: FnMut(&'lua Lua, A) -> Result<R> + MaybeSend + 'static,
{
let func = RefCell::new(func);
self.create_function(move |lua, args| {
@@ -1617,8 +1616,8 @@ impl Lua {
where
A: FromLuaMulti<'lua>,
R: IntoLuaMulti<'lua>,
- F: 'static + MaybeSend + Fn(&'lua Lua, A) -> FR,
- FR: 'lua + Future<Output = Result<R>>,
+ F: Fn(&'lua Lua, A) -> FR + MaybeSend + 'static,
+ FR: Future<Output = Result<R>> + 'lua,
{
self.create_async_callback(Box::new(move |lua, args| {
let args = match A::from_lua_multi_args(args, 1, None, lua) {
@@ -1820,7 +1819,7 @@ impl Lua {
#[inline]
pub fn create_proxy<T>(&self) -> Result<AnyUserData>
where
- T: 'static + UserData,
+ T: UserData + 'static,
{
unsafe { self.make_userdata(UserDataCell::new(UserDataProxy::<T>(PhantomData))) }
}
@@ -2640,7 +2639,7 @@ impl Lua {
#[cfg(feature = "luau")]
let extra_init = None;
#[cfg(not(feature = "luau"))]
- let extra_init: Option<&dyn Fn(*mut ffi::lua_State) -> Result<()>> = Some(&|state| {
+ let extra_init: Option<fn(*mut ffi::lua_State) -> Result<()>> = Some(|state| {
ffi::lua_pushcfunction(state, util::userdata_destructor::<UserDataCell<T>>);
rawset_field(state, -2, "__gc")
});
diff --git a/src/scope.rs b/src/scope.rs
index 7a190a9..15d1b56 100644
--- a/src/scope.rs
+++ b/src/scope.rs
@@ -438,7 +438,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
#[cfg(feature = "luau")]
let extra_init = None;
#[cfg(not(feature = "luau"))]
- let extra_init: Option<&dyn Fn(*mut ffi::lua_State) -> Result<()>> = Some(&|state| {
+ let extra_init: Option<fn(*mut ffi::lua_State) -> Result<()>> = Some(|state| {
ffi::lua_pushcfunction(state, util::userdata_destructor::<UserDataCell<T>>);
rawset_field(state, -2, "__gc")
});
diff --git a/src/thread.rs b/src/thread.rs
index 44fa860..75a6851 100644
--- a/src/thread.rs
+++ b/src/thread.rs
@@ -8,13 +8,6 @@ use crate::types::LuaRef;
use crate::util::{check_stack, error_traceback_thread, pop_error, StackGuard};
use crate::value::{FromLuaMulti, IntoLuaMulti};
-#[cfg(any(
- feature = "lua54",
- all(feature = "luajit", feature = "vendored"),
- feature = "luau",
-))]
-use crate::function::Function;
-
#[cfg(not(feature = "luau"))]
use crate::{
hook::{Debug, HookTriggers},
@@ -60,14 +53,14 @@ pub struct Thread<'lua>(pub(crate) LuaRef<'lua>);
///
/// Requires `feature = "async"`
///
-/// [`Future`]: futures_core::future::Future
-/// [`Stream`]: futures_core::stream::Stream
+/// [`Future`]: std::future::Future
+/// [`Stream`]: futures_util::stream::Stream
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct AsyncThread<'lua, R> {
thread: Thread<'lua>,
- args0: Option<Result<MultiValue<'lua>>>,
+ init_args: Option<Result<MultiValue<'lua>>>,
ret: PhantomData<R>,
recycle: bool,
}
@@ -223,7 +216,7 @@ impl<'lua> Thread<'lua> {
all(feature = "luajit", feature = "vendored"),
feature = "luau",
))]
- pub fn reset(&self, func: Function<'lua>) -> Result<()> {
+ pub fn reset(&self, func: crate::function::Function<'lua>) -> Result<()> {
let lua = self.0.lua;
let state = lua.state();
unsafe {
@@ -272,8 +265,8 @@ impl<'lua> Thread<'lua> {
///
/// Requires `feature = "async"`
///
- /// [`Future`]: futures_core::future::Future
- /// [`Stream`]: futures_core::stream::Stream
+ /// [`Future`]: std::future::Future
+ /// [`Stream`]: futures_util::stream::Stream
/// [`resume()`]: https://www.lua.org/manual/5.4/manual.html#lua_resume
///
/// # Examples
@@ -315,7 +308,7 @@ impl<'lua> Thread<'lua> {
let args = args.into_lua_multi(self.0.lua);
AsyncThread {
thread: self,
- args0: Some(args),
+ init_args: Some(args),
ret: PhantomData,
recycle: false,
}
@@ -427,7 +420,7 @@ where
// This is safe as we are not moving the whole struct
let this = unsafe { self.get_unchecked_mut() };
- let ret: MultiValue = if let Some(args) = this.args0.take() {
+ let ret: MultiValue = if let Some(args) = this.init_args.take() {
this.thread.resume(args?)?
} else {
this.thread.resume(())?
@@ -461,7 +454,7 @@ where
// This is safe as we are not moving the whole struct
let this = unsafe { self.get_unchecked_mut() };
- let ret: MultiValue = if let Some(args) = this.args0.take() {
+ let ret: MultiValue = if let Some(args) = this.init_args.take() {
this.thread.resume(args?)?
} else {
this.thread.resume(())?
diff --git a/src/userdata_impl.rs b/src/userdata_impl.rs
index 3701ef3..ae67132 100644
--- a/src/userdata_impl.rs
+++ b/src/userdata_impl.rs
@@ -26,6 +26,7 @@ use {
std::future::Future,
};
+/// Handle to registry for userdata methods and metamethods.
pub struct UserDataRegistrar<'lua, T: 'static> {
// Fields
pub(crate) fields: Vec<(String, Callback<'lua, 'static>)>,
diff --git a/src/util/mod.rs b/src/util/mod.rs
index 9831208..b125413 100644
--- a/src/util/mod.rs
+++ b/src/util/mod.rs
@@ -552,7 +552,7 @@ pub unsafe fn init_userdata_metatable(
field_getters: Option<c_int>,
field_setters: Option<c_int>,
methods: Option<c_int>,
- extra_init: Option<&dyn Fn(*mut ffi::lua_State) -> Result<()>>,
+ extra_init: Option<fn(*mut ffi::lua_State) -> Result<()>>,
) -> Result<()> {
ffi::lua_pushvalue(state, metatable);