From 59788d911647287342be4196832989950f282f57 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sun, 20 Aug 2023 18:56:28 -0500 Subject: [PATCH] Use app data for net builtin client --- src/lune/builtins/net/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lune/builtins/net/mod.rs b/src/lune/builtins/net/mod.rs index 552fd55..c06d0f1 100644 --- a/src/lune/builtins/net/mod.rs +++ b/src/lune/builtins/net/mod.rs @@ -35,7 +35,7 @@ pub fn create(lua: &'static Lua) -> LuaResult { let client = NetClientBuilder::new() .headers(&[("User-Agent", create_user_agent_header())])? .build()?; - lua.set_named_registry_value("net.client", client)?; + lua.set_app_data(client); // Create the global table for net TableBuilder::new(lua)? .with_function("jsonEncode", net_json_encode)? @@ -73,7 +73,9 @@ where 'lua: 'static, // FIXME: Get rid of static lifetime bound here { // Create and send the request - let client: LuaUserDataRef = lua.named_registry_value("net.client")?; + let client = lua + .app_data_ref::() + .expect("Missing net client in lua app data"); let mut request = client.request(config.method, &config.url); for (query, value) in config.query { request = request.query(&[(query.to_str()?, value.to_str()?)]);