mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
Add Function::wrap/Function::wrap_mut/Function::wrap_async to wrap functions into a type that implements IntoLua trait.
This is useful to avoid calling `lua.create_function*` every time when `Function` handle is needed.
This commit is contained in:
+24
-1
@@ -19,7 +19,14 @@ use crate::userdata::{AnyUserData, UserData};
|
||||
use crate::value::{FromLua, IntoLua, Nil, Value};
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
use crate::{function::OwnedFunction, table::OwnedTable, userdata::OwnedAnyUserData};
|
||||
use crate::{
|
||||
function::{OwnedFunction, WrappedFunction},
|
||||
table::OwnedTable,
|
||||
userdata::OwnedAnyUserData,
|
||||
};
|
||||
|
||||
#[cfg(all(feature = "async", feature = "unstable"))]
|
||||
use crate::function::WrappedAsyncFunction;
|
||||
|
||||
impl<'lua> IntoLua<'lua> for Value<'lua> {
|
||||
#[inline]
|
||||
@@ -129,6 +136,22 @@ impl<'lua> FromLua<'lua> for OwnedFunction {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
impl<'lua> IntoLua<'lua> for WrappedFunction<'lua> {
|
||||
#[inline]
|
||||
fn into_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
||||
lua.create_callback(self.0).map(Value::Function)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "async", feature = "unstable"))]
|
||||
impl<'lua> IntoLua<'lua> for WrappedAsyncFunction<'lua> {
|
||||
#[inline]
|
||||
fn into_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
||||
lua.create_async_callback(self.0).map(Value::Function)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'lua> IntoLua<'lua> for Thread<'lua> {
|
||||
#[inline]
|
||||
fn into_lua(self, _: &'lua Lua) -> Result<Value<'lua>> {
|
||||
|
||||
Reference in New Issue
Block a user