File tree Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -911,12 +911,11 @@ impl RawLua {
911
911
let _sg = StackGuard :: new ( state) ;
912
912
check_stack ( state, 3 ) ?;
913
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 ( ) ?) ;
914
+ // We generate metatable first to make sure it *always* available when userdata pushed
915
+ let mt_id = get_metatable_id ( ) ?;
917
916
let protect = !self . unlikely_memory_error ( ) ;
918
917
crate :: util:: push_userdata ( state, data, protect) ?;
919
- ffi:: lua_replace ( state, - 3 ) ;
918
+ ffi:: lua_rawgeti ( state, ffi :: LUA_REGISTRYINDEX , mt_id ) ;
920
919
ffi:: lua_setmetatable ( state, -2 ) ;
921
920
922
921
// Set empty environment for Lua 5.1
You can’t perform that action at this time.
0 commit comments