setmetatable should return the table

This commit is contained in:
kyren 2017-08-02 15:56:16 -04:00
parent 9c34d4b99f
commit c3c7d8c093
2 changed files with 15 additions and 3 deletions

View file

@ -904,19 +904,31 @@ fn test_pcall_xpcall() {
xpcall_error = nil
xpcall(error, function(err) xpcall_error = err end, "testerror")
function xpcall_recursion()
xpcall(error, function(err) error(err) end, "testerror")
end
"#,
None,
).unwrap();
let globals = lua.globals();
assert_eq!(
lua.globals().get::<_, String>("pcall_error").unwrap(),
globals.get::<_, String>("pcall_error").unwrap(),
"testerror"
);
assert_eq!(
lua.globals().get::<_, String>("xpcall_error").unwrap(),
globals.get::<_, String>("xpcall_error").unwrap(),
"testerror"
);
// Make sure that weird xpcall error recursion at least doesn't cause unsafety or panics.
let _ = globals
.get::<_, Function>("xpcall_recursion")
.unwrap()
.call::<_, ()>(());
}
#[test]

View file

@ -520,7 +520,7 @@ pub unsafe extern "C" fn safe_setmetatable(state: *mut ffi::lua_State) -> c_int
ffi::lua_pop(state, 1);
}
ffi::lua_setmetatable(state, -2);
0
1
}
// Does not call checkstack, uses 1 stack space