pub struct Scope<'scope> { /* private fields */ }Expand description
Constructed by the Lua::scope method, allows temporarily passing to Lua userdata that is
!Send, and callbacks that are !Send and not ’static.
See Lua::scope for more details.
Implementations
sourceimpl<'scope> Scope<'scope>
impl<'scope> Scope<'scope>
sourcepub fn create_function<'lua, A, R, F>(
&'lua self,
func: F
) -> Result<Function<'lua>, Error>where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'scope + Fn(&'lua Lua, A) -> Result<R, Error>,
pub fn create_function<'lua, A, R, F>(
&'lua self,
func: F
) -> Result<Function<'lua>, Error>where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'scope + Fn(&'lua Lua, A) -> Result<R, Error>,
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<'lua, A, R, F>(
&'lua self,
func: F
) -> Result<Function<'lua>, Error>where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'scope + FnMut(&'lua Lua, A) -> Result<R, Error>,
pub fn create_function_mut<'lua, A, R, F>(
&'lua self,
func: F
) -> Result<Function<'lua>, Error>where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'scope + FnMut(&'lua Lua, A) -> Result<R, Error>,
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_static_userdata<T, 'lua>(
&'lua self,
data: T
) -> Result<AnyUserData<'lua>, Error>where
T: 'static + UserData,
pub fn create_static_userdata<T, 'lua>(
&'lua self,
data: T
) -> Result<AnyUserData<'lua>, Error>where
T: 'static + UserData,
Create 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_nonstatic_userdata<T, 'lua>(
&'lua self,
data: T
) -> Result<AnyUserData<'lua>, Error>where
T: 'scope + UserData,
pub fn create_nonstatic_userdata<T, 'lua>(
&'lua self,
data: T
) -> Result<AnyUserData<'lua>, Error>where
T: 'scope + UserData,
Create 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_static_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, becuase 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.