diff --git a/src/lua.rs b/src/lua.rs index 4284c8c..4ea11c2 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -970,14 +970,14 @@ impl Lua { let _sg = StackGuard::new(self.state); assert_stack(self.state, 4); + let ud_index = self.userdata_metatable::()?; push_userdata::>(self.state, RefCell::new(data))?; ffi::lua_rawgeti( self.state, ffi::LUA_REGISTRYINDEX, - self.userdata_metatable::()? as ffi::lua_Integer, + ud_index as ffi::lua_Integer, ); - ffi::lua_setmetatable(self.state, -2); Ok(AnyUserData(self.pop_ref()))