Rename Scope::create_userdata to Scope::create_nonstatic_userdata

avoids clashing with the previous method name to avoid confusion
This commit is contained in:
kyren 2018-09-16 19:54:12 -04:00
parent 58b991b83b
commit 7eb71fb1df
2 changed files with 11 additions and 10 deletions

View File

@ -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<AnyUserData<'lua>>
pub fn create_nonstatic_userdata<'lua, T>(&'lua self, data: T) -> Result<AnyUserData<'lua>>
where
T: 'scope + UserData,
{
@ -160,11 +160,12 @@ impl<'scope> Scope<'scope> {
method: NonStaticMethod<'callback, T>,
) -> Result<Function<'lua>> {
// 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 {

View File

@ -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() {