From 616846c31641c2fcfccb227c61f00a0c270dfbf4 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sun, 20 Aug 2023 19:26:34 -0500 Subject: [PATCH] Fix web sockets using old registry values --- src/lune/builtins/net/websocket.rs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/lune/builtins/net/websocket.rs b/src/lune/builtins/net/websocket.rs index 36fc7b1..2bd7c5a 100644 --- a/src/lune/builtins/net/websocket.rs +++ b/src/lune/builtins/net/websocket.rs @@ -89,20 +89,19 @@ where type NetWebSocketStreamClient = MaybeTlsStream; impl NetWebSocket { pub fn into_lua_table(self, lua: &'static Lua) -> LuaResult { + let setmetatable = lua.globals().get::<_, LuaFunction>("setmetatable")?; + let table_freeze = lua + .globals() + .get::<_, LuaTable>("table")? + .get::<_, LuaFunction>("freeze")?; let socket_env = TableBuilder::new(lua)? .with_value("websocket", self)? .with_function("close_code", close_code::)? .with_async_function("close", close::)? .with_async_function("send", send::)? .with_async_function("next", next::)? - .with_value( - "setmetatable", - lua.named_registry_value::("tab.setmeta")?, - )? - .with_value( - "freeze", - lua.named_registry_value::("tab.freeze")?, - )? + .with_value("setmetatable", setmetatable)? + .with_value("freeze", table_freeze)? .build_readonly()?; Self::into_lua_table_with_env(lua, socket_env) } @@ -111,20 +110,19 @@ impl NetWebSocket { type NetWebSocketStreamServer = Upgraded; impl NetWebSocket { pub fn into_lua_table(self, lua: &'static Lua) -> LuaResult { + let setmetatable = lua.globals().get::<_, LuaFunction>("setmetatable")?; + let table_freeze = lua + .globals() + .get::<_, LuaTable>("table")? + .get::<_, LuaFunction>("freeze")?; let socket_env = TableBuilder::new(lua)? .with_value("websocket", self)? .with_function("close_code", close_code::)? .with_async_function("close", close::)? .with_async_function("send", send::)? .with_async_function("next", next::)? - .with_value( - "setmetatable", - lua.named_registry_value::("tab.setmeta")?, - )? - .with_value( - "freeze", - lua.named_registry_value::("tab.freeze")?, - )? + .with_value("setmetatable", setmetatable)? + .with_value("freeze", table_freeze)? .build_readonly()?; Self::into_lua_table_with_env(lua, socket_env) }