From c3c7d8c0931c83642e257c959dcc0650f2473bb6 Mon Sep 17 00:00:00 2001 From: kyren Date: Wed, 2 Aug 2017 15:56:16 -0400 Subject: [PATCH] setmetatable should return the table --- src/tests.rs | 16 ++++++++++++++-- src/util.rs | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/tests.rs b/src/tests.rs index 13dc671..3ac86fc 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -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] diff --git a/src/util.rs b/src/util.rs index 2acaabf..751223d 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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