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 {
911911 let _sg = StackGuard :: new ( state) ;
912912 check_stack ( state, 3 ) ?;
913913
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 ( ) ?;
917916 let protect = !self . unlikely_memory_error ( ) ;
918917 crate :: util:: push_userdata ( state, data, protect) ?;
919- ffi:: lua_replace ( state, - 3 ) ;
918+ ffi:: lua_rawgeti ( state, ffi :: LUA_REGISTRYINDEX , mt_id ) ;
920919 ffi:: lua_setmetatable ( state, -2 ) ;
921920
922921 // Set empty environment for Lua 5.1
You can’t perform that action at this time.
0 commit comments