We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b0140cd commit 8d864e2Copy full SHA for 8d864e2
src/state/raw.rs
@@ -911,12 +911,11 @@ impl RawLua {
911
let _sg = StackGuard::new(state);
912
check_stack(state, 3)?;
913
914
- // We push metatable first to ensure having correct metatable with `__gc` method
915
- ffi::lua_pushnil(state);
916
- ffi::lua_rawgeti(state, ffi::LUA_REGISTRYINDEX, get_metatable_id()?);
+ // We generate metatable first to make sure it *always* available when userdata pushed
+ let mt_id = get_metatable_id()?;
917
let protect = !self.unlikely_memory_error();
918
crate::util::push_userdata(state, data, protect)?;
919
- ffi::lua_replace(state, -3);
+ ffi::lua_rawgeti(state, ffi::LUA_REGISTRYINDEX, mt_id);
920
ffi::lua_setmetatable(state, -2);
921
922
// Set empty environment for Lua 5.1
0 commit comments