mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Use app data for net builtin client
This commit is contained in:
parent
59aef5c170
commit
59788d9116
1 changed files with 4 additions and 2 deletions
|
@ -35,7 +35,7 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
|
||||||
let client = NetClientBuilder::new()
|
let client = NetClientBuilder::new()
|
||||||
.headers(&[("User-Agent", create_user_agent_header())])?
|
.headers(&[("User-Agent", create_user_agent_header())])?
|
||||||
.build()?;
|
.build()?;
|
||||||
lua.set_named_registry_value("net.client", client)?;
|
lua.set_app_data(client);
|
||||||
// Create the global table for net
|
// Create the global table for net
|
||||||
TableBuilder::new(lua)?
|
TableBuilder::new(lua)?
|
||||||
.with_function("jsonEncode", net_json_encode)?
|
.with_function("jsonEncode", net_json_encode)?
|
||||||
|
@ -73,7 +73,9 @@ where
|
||||||
'lua: 'static, // FIXME: Get rid of static lifetime bound here
|
'lua: 'static, // FIXME: Get rid of static lifetime bound here
|
||||||
{
|
{
|
||||||
// Create and send the request
|
// Create and send the request
|
||||||
let client: LuaUserDataRef<NetClient> = lua.named_registry_value("net.client")?;
|
let client = lua
|
||||||
|
.app_data_ref::<NetClient>()
|
||||||
|
.expect("Missing net client in lua app data");
|
||||||
let mut request = client.request(config.method, &config.url);
|
let mut request = client.request(config.method, &config.url);
|
||||||
for (query, value) in config.query {
|
for (query, value) in config.query {
|
||||||
request = request.query(&[(query.to_str()?, value.to_str()?)]);
|
request = request.query(&[(query.to_str()?, value.to_str()?)]);
|
||||||
|
|
Loading…
Reference in a new issue