Rename Scope::create_userdata to Scope::create_nonstatic_userdata
avoids clashing with the previous method name to avoid confusion
This commit is contained in:
parent
58b991b83b
commit
7eb71fb1df
13
src/scope.rs
13
src/scope.rs
|
@ -144,7 +144,7 @@ impl<'scope> Scope<'scope> {
|
||||||
/// [`Lua::create_userdata`]: struct.Lua.html#method.create_userdata
|
/// [`Lua::create_userdata`]: struct.Lua.html#method.create_userdata
|
||||||
/// [`Lua::scope`]: struct.Lua.html#method.scope
|
/// [`Lua::scope`]: struct.Lua.html#method.scope
|
||||||
/// [`UserDataMethods`]: trait.UserDataMethods.html
|
/// [`UserDataMethods`]: trait.UserDataMethods.html
|
||||||
pub fn create_userdata<'lua, T>(&'lua self, data: T) -> Result<AnyUserData<'lua>>
|
pub fn create_nonstatic_userdata<'lua, T>(&'lua self, data: T) -> Result<AnyUserData<'lua>>
|
||||||
where
|
where
|
||||||
T: 'scope + UserData,
|
T: 'scope + UserData,
|
||||||
{
|
{
|
||||||
|
@ -160,11 +160,12 @@ impl<'scope> Scope<'scope> {
|
||||||
method: NonStaticMethod<'callback, T>,
|
method: NonStaticMethod<'callback, T>,
|
||||||
) -> Result<Function<'lua>> {
|
) -> Result<Function<'lua>> {
|
||||||
// On methods that actually receive the userdata, we fake a type check on the passed in
|
// On methods that actually receive the userdata, we fake a type check on the passed in
|
||||||
// userdata, where we pretend there is a unique type per call to Scope::create_userdata.
|
// userdata, where we pretend there is a unique type per call to
|
||||||
// You can grab a method from a userdata and call it on a mismatched userdata type,
|
// Scope::create_nonstatic_userdata. You can grab a method from a userdata and call it
|
||||||
// which when using normal 'static userdata will fail with a type mismatch, but here
|
// on a mismatched userdata type, which when using normal 'static userdata will fail
|
||||||
// without this check would proceed as though you had called the method on the original
|
// with a type mismatch, but here without this check would proceed as though you had
|
||||||
// value (since we otherwise completely ignore the first argument).
|
// called the method on the original value (since we otherwise completely ignore the
|
||||||
|
// first argument).
|
||||||
let check_data = data.clone();
|
let check_data = data.clone();
|
||||||
let check_ud_type = move |lua: &Lua, value| {
|
let check_ud_type = move |lua: &Lua, value| {
|
||||||
if let Some(value) = value {
|
if let Some(value) = value {
|
||||||
|
|
|
@ -136,7 +136,7 @@ fn scope_userdata_methods() {
|
||||||
None,
|
None,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
f.call::<_, ()>(scope.create_userdata(MyUserData(&i)).unwrap())
|
f.call::<_, ()>(scope.create_nonstatic_userdata(MyUserData(&i)).unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ fn scope_userdata_functions() {
|
||||||
|
|
||||||
let dummy = 0;
|
let dummy = 0;
|
||||||
lua.scope(|scope| {
|
lua.scope(|scope| {
|
||||||
f.call::<_, ()>(scope.create_userdata(MyUserData(&dummy)).unwrap())
|
f.call::<_, ()>(scope.create_nonstatic_userdata(MyUserData(&dummy)).unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -220,8 +220,8 @@ fn scope_userdata_mismatch() {
|
||||||
let bad: Function = lua.globals().get("bad").unwrap();
|
let bad: Function = lua.globals().get("bad").unwrap();
|
||||||
|
|
||||||
lua.scope(|scope| {
|
lua.scope(|scope| {
|
||||||
let au = scope.create_userdata(MyUserData(&a)).unwrap();
|
let au = scope.create_nonstatic_userdata(MyUserData(&a)).unwrap();
|
||||||
let bu = scope.create_userdata(MyUserData(&b)).unwrap();
|
let bu = scope.create_nonstatic_userdata(MyUserData(&b)).unwrap();
|
||||||
assert!(okay.call::<_, ()>((au.clone(), bu.clone())).is_ok());
|
assert!(okay.call::<_, ()>((au.clone(), bu.clone())).is_ok());
|
||||||
match bad.call::<_, ()>((au, bu)) {
|
match bad.call::<_, ()>((au, bu)) {
|
||||||
Err(Error::CallbackError { ref cause, .. }) => match *cause.as_ref() {
|
Err(Error::CallbackError { ref cause, .. }) => match *cause.as_ref() {
|
||||||
|
|
Loading…
Reference in New Issue