Merge pull request #55 from Timidger/bugfix/setting_metatable_nil
Fixes error when setting metatable to nil
This commit is contained in:
commit
cf013a6a43
10
src/tests.rs
10
src/tests.rs
|
@ -629,6 +629,16 @@ fn test_recursive_callback_panic() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_set_metatable_nil() {
|
||||||
|
let lua = Lua::new();
|
||||||
|
lua.exec::<()>(
|
||||||
|
r#"
|
||||||
|
a = {}
|
||||||
|
setmetatable(a, nil)
|
||||||
|
"#, None).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Need to use compiletest-rs or similar to make sure these don't compile.
|
// TODO: Need to use compiletest-rs or similar to make sure these don't compile.
|
||||||
/*
|
/*
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -512,7 +512,7 @@ pub unsafe extern "C" fn safe_setmetatable(state: *mut ffi::lua_State) -> c_int
|
||||||
// Wrapping the __gc method in setmetatable ONLY works because Lua 5.3 only honors the __gc
|
// Wrapping the __gc method in setmetatable ONLY works because Lua 5.3 only honors the __gc
|
||||||
// method when it exists upon calling setmetatable, and ignores it if it is set later.
|
// method when it exists upon calling setmetatable, and ignores it if it is set later.
|
||||||
push_string(state, "__gc");
|
push_string(state, "__gc");
|
||||||
if ffi::lua_rawget(state, -2) == ffi::LUA_TFUNCTION {
|
if ffi::lua_istable(state, -2) == 1 && ffi::lua_rawget(state, -2) == ffi::LUA_TFUNCTION {
|
||||||
unsafe extern "C" fn safe_gc(state: *mut ffi::lua_State) -> c_int {
|
unsafe extern "C" fn safe_gc(state: *mut ffi::lua_State) -> c_int {
|
||||||
ffi::lua_pushvalue(state, ffi::lua_upvalueindex(1));
|
ffi::lua_pushvalue(state, ffi::lua_upvalueindex(1));
|
||||||
ffi::lua_insert(state, 1);
|
ffi::lua_insert(state, 1);
|
||||||
|
|
Loading…
Reference in New Issue