diff --git a/src/scope.rs b/src/scope.rs index 5820c3e..a724b29 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -144,7 +144,7 @@ impl<'scope> Scope<'scope> { /// [`Lua::create_userdata`]: struct.Lua.html#method.create_userdata /// [`Lua::scope`]: struct.Lua.html#method.scope /// [`UserDataMethods`]: trait.UserDataMethods.html - pub fn create_userdata<'lua, T>(&'lua self, data: T) -> Result> + pub fn create_nonstatic_userdata<'lua, T>(&'lua self, data: T) -> Result> where T: 'scope + UserData, { @@ -160,11 +160,12 @@ impl<'scope> Scope<'scope> { method: NonStaticMethod<'callback, T>, ) -> Result> { // 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. - // You can grab a method from a userdata and call it on a mismatched userdata type, - // which when using normal 'static userdata will fail with a type mismatch, but here - // without this check would proceed as though you had called the method on the original - // value (since we otherwise completely ignore the first argument). + // userdata, where we pretend there is a unique type per call to + // Scope::create_nonstatic_userdata. You can grab a method from a userdata and call it + // on a mismatched userdata type, which when using normal 'static userdata will fail + // with a type mismatch, but here without this check would proceed as though you had + // called the method on the original value (since we otherwise completely ignore the + // first argument). let check_data = data.clone(); let check_ud_type = move |lua: &Lua, value| { if let Some(value) = value { diff --git a/src/tests/scope.rs b/src/tests/scope.rs index 0d04acc..0373569 100644 --- a/src/tests/scope.rs +++ b/src/tests/scope.rs @@ -136,7 +136,7 @@ fn scope_userdata_methods() { None, ).unwrap(); - f.call::<_, ()>(scope.create_userdata(MyUserData(&i)).unwrap()) + f.call::<_, ()>(scope.create_nonstatic_userdata(MyUserData(&i)).unwrap()) .unwrap(); }); @@ -178,7 +178,7 @@ fn scope_userdata_functions() { let dummy = 0; lua.scope(|scope| { - f.call::<_, ()>(scope.create_userdata(MyUserData(&dummy)).unwrap()) + f.call::<_, ()>(scope.create_nonstatic_userdata(MyUserData(&dummy)).unwrap()) .unwrap(); }); @@ -220,8 +220,8 @@ fn scope_userdata_mismatch() { let bad: Function = lua.globals().get("bad").unwrap(); lua.scope(|scope| { - let au = scope.create_userdata(MyUserData(&a)).unwrap(); - let bu = scope.create_userdata(MyUserData(&b)).unwrap(); + let au = scope.create_nonstatic_userdata(MyUserData(&a)).unwrap(); + let bu = scope.create_nonstatic_userdata(MyUserData(&b)).unwrap(); assert!(okay.call::<_, ()>((au.clone(), bu.clone())).is_ok()); match bad.call::<_, ()>((au, bu)) { Err(Error::CallbackError { ref cause, .. }) => match *cause.as_ref() {