pub struct Scope<'lua, 'scope>where
'lua: 'scope,{ /* private fields */ }
Expand description
Constructed by the Lua::scope
method, allows temporarily creating Lua userdata and
callbacks that are not required to be Send or ’static.
See Lua::scope
for more details.
Implementations§
source§impl<'lua, 'scope> Scope<'lua, 'scope>
impl<'lua, 'scope> Scope<'lua, 'scope>
sourcepub fn create_function<'callback, A, R, F>(
&'callback self,
func: F
) -> Result<Function<'lua>, Error>where
A: FromLuaMulti<'callback>,
R: IntoLuaMulti<'callback>,
F: Fn(&'callback Lua, A) -> Result<R, Error> + 'scope,
pub fn create_function<'callback, A, R, F>(
&'callback self,
func: F
) -> Result<Function<'lua>, Error>where
A: FromLuaMulti<'callback>,
R: IntoLuaMulti<'callback>,
F: Fn(&'callback Lua, A) -> Result<R, Error> + 'scope,
Wraps a Rust function or closure, creating a callable Lua function handle to it.
This is a version of Lua::create_function
that creates a callback which expires on
scope drop. See Lua::scope
for more details.
sourcepub fn create_function_mut<'callback, A, R, F>(
&'callback self,
func: F
) -> Result<Function<'lua>, Error>where
A: FromLuaMulti<'callback>,
R: IntoLuaMulti<'callback>,
F: FnMut(&'callback Lua, A) -> Result<R, Error> + 'scope,
pub fn create_function_mut<'callback, A, R, F>(
&'callback self,
func: F
) -> Result<Function<'lua>, Error>where
A: FromLuaMulti<'callback>,
R: IntoLuaMulti<'callback>,
F: FnMut(&'callback Lua, A) -> Result<R, Error> + 'scope,
Wraps a Rust mutable closure, creating a callable Lua function handle to it.
This is a version of Lua::create_function_mut
that creates a callback which expires
on scope drop. See Lua::scope
and Scope::create_function
for more details.
sourcepub fn create_userdata<T>(&self, data: T) -> Result<AnyUserData<'lua>, Error>where
T: UserData + 'static,
pub fn create_userdata<T>(&self, data: T) -> Result<AnyUserData<'lua>, Error>where
T: UserData + 'static,
Creates a Lua userdata object from a custom userdata type.
This is a version of Lua::create_userdata
that creates a userdata which expires on
scope drop, and does not require that the userdata type be Send (but still requires that the
UserData be ’static).
See Lua::scope
for more details.
sourcepub fn create_userdata_ref<T>(
&self,
data: &'scope T
) -> Result<AnyUserData<'lua>, Error>where
T: UserData + 'static,
pub fn create_userdata_ref<T>(
&self,
data: &'scope T
) -> Result<AnyUserData<'lua>, Error>where
T: UserData + 'static,
Creates a Lua userdata object from a reference to custom userdata type.
This is a version of Lua::create_userdata
that creates a userdata which expires on
scope drop, and does not require that the userdata type be Send. This method takes non-’static
reference to the data. See Lua::scope
for more details.
Userdata created with this method will not be able to be mutated from Lua.
sourcepub fn create_userdata_ref_mut<T>(
&self,
data: &'scope mut T
) -> Result<AnyUserData<'lua>, Error>where
T: UserData + 'static,
pub fn create_userdata_ref_mut<T>(
&self,
data: &'scope mut T
) -> Result<AnyUserData<'lua>, Error>where
T: UserData + 'static,
Creates a Lua userdata object from a mutable reference to custom userdata type.
This is a version of Lua::create_userdata
that creates a userdata which expires on
scope drop, and does not require that the userdata type be Send. This method takes non-’static
mutable reference to the data. See Lua::scope
for more details.
sourcepub fn create_any_userdata<T>(
&self,
data: T
) -> Result<AnyUserData<'lua>, Error>where
T: 'static,
pub fn create_any_userdata<T>(
&self,
data: T
) -> Result<AnyUserData<'lua>, Error>where
T: 'static,
Creates a Lua userdata object from a custom Rust type.
This is a version of Lua::create_any_userdata
that creates a userdata which expires on
scope drop and does not require that the userdata type be Send (but still requires that the
UserData be ’static). See Lua::scope
for more details.
sourcepub fn create_any_userdata_ref<T>(
&self,
data: &'scope T
) -> Result<AnyUserData<'lua>, Error>where
T: 'static,
pub fn create_any_userdata_ref<T>(
&self,
data: &'scope T
) -> Result<AnyUserData<'lua>, Error>where
T: 'static,
Creates a Lua userdata object from a reference to custom Rust type.
This is a version of Lua::create_any_userdata
that creates a userdata which expires on
scope drop, and does not require that the Rust type be Send. This method takes non-’static
reference to the data. See Lua::scope
for more details.
Userdata created with this method will not be able to be mutated from Lua.
sourcepub fn create_any_userdata_ref_mut<T>(
&self,
data: &'scope mut T
) -> Result<AnyUserData<'lua>, Error>where
T: 'static,
pub fn create_any_userdata_ref_mut<T>(
&self,
data: &'scope mut T
) -> Result<AnyUserData<'lua>, Error>where
T: 'static,
Creates a Lua userdata object from a mutable reference to custom Rust type.
This is a version of Lua::create_any_userdata
that creates a userdata which expires on
scope drop, and does not require that the Rust type be Send. This method takes non-’static
mutable reference to the data. See Lua::scope
for more details.
sourcepub fn create_nonstatic_userdata<T>(
&self,
data: T
) -> Result<AnyUserData<'lua>, Error>where
T: UserData + 'scope,
pub fn create_nonstatic_userdata<T>(
&self,
data: T
) -> Result<AnyUserData<'lua>, Error>where
T: UserData + 'scope,
Creates a Lua userdata object from a custom userdata type.
This is a version of Lua::create_userdata
that creates a userdata which expires on
scope drop, and does not require that the userdata type be Send or ’static. See
Lua::scope
for more details.
Lifting the requirement that the UserData type be ’static comes with some important
limitations, so if you only need to eliminate the Send requirement, it is probably better to
use Scope::create_userdata
instead.
The main limitation that comes from using non-’static userdata is that the produced userdata
will no longer have a TypeId
associated with it, because TypeId
can only work for
’static types. This means that it is impossible, once the userdata is created, to get a
reference to it back out of an AnyUserData
handle. This also implies that the
“function” type methods that can be added via UserDataMethods
(the ones that accept
AnyUserData
as a first parameter) are vastly less useful. Also, there is no way to re-use
a single metatable for multiple non-’static types, so there is a higher cost associated with
creating the userdata metatable each time a new userdata is created.