Skip to content

Commit 31b2072

Browse files
committed
Upgrade to mlua 0.12.2
1 parent 5ccba98 commit 31b2072

22 files changed

Lines changed: 139 additions & 67 deletions

‎.github/workflows/ci.yml‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ jobs:
99
fail-fast: false
1010
matrix:
1111
os: [ubuntu-latest]
12-
lua: [lua52, lua53, lua54, luau]
12+
lua: [lua52, lua53, lua54, lua55, luau]
13+
send: ["", ",send"]
1314
steps:
1415
- uses: actions/checkout@main
1516
- name: Cache cargo
@@ -22,10 +23,10 @@ jobs:
2223
- uses: dtolnay/rust-toolchain@stable
2324
- name: Run ${{ matrix.lua }} tests (basic)
2425
run: |
25-
cargo test --features ${{ matrix.lua }},vendored
26+
cargo test --features ${{ matrix.lua }},vendored${{ matrix.send }} -- --test-threads=1
2627
- name: Run ${{ matrix.lua }} tests (full)
2728
run: |
28-
cargo test --features ${{ matrix.lua }},vendored,json,regex,yaml,http,task,net,tls
29+
cargo test --features ${{ matrix.lua }},vendored,json,regex,yaml,http,reqwest,task,net,tls${{ matrix.send }} -- --test-threads=1
2930
3031
rustfmt:
3132
name: Rustfmt
@@ -53,4 +54,4 @@ jobs:
5354
with:
5455
components: clippy
5556
- run: |
56-
cargo clippy --features lua54,vendored,json,regex,yaml,http,task,net,tls -- -D warnings
57+
cargo clippy --features lua55,vendored,json,regex,yaml,http,reqwest,task,net,tls -- -D warnings

‎Cargo.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ lua51 = ["mlua/lua51"]
1212
lua52 = ["mlua/lua52"]
1313
lua53 = ["mlua/lua53"]
1414
lua54 = ["mlua/lua54"]
15+
lua55 = ["mlua/lua55"]
1516
luau = ["mlua/luau"]
1617
async = ["mlua/async", "dep:tokio", "dep:tokio-util", "dep:futures-util"]
1718
send = ["mlua/send"]
@@ -28,7 +29,7 @@ tls = ["net", "dep:rustls", "dep:tokio-rustls", "dep:rustls-pemfile", "dep:rustl
2829

2930
[dependencies]
3031
bytes = "1"
31-
mlua = { version = "0.11.5", features = ["error-send", "macros"] }
32+
mlua = { version = "0.12.2", features = ["error-send", "macros"] }
3233
ouroboros = { version = "0.18", optional = true }
3334
serde = { version = "1.0", optional = true }
3435
serde_json = { version = "1.0", optional = true }

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ With the following optional modules:
2828

2929
The following feature flags are passed to `mlua`, when enabled:
3030

31-
- `lua51`, `lua52`, `lua53`, `lua54`, `luau` - Lua version selection
31+
- `lua51`, `lua52`, `lua53`, `lua54`, `lua55`, `luau` - Lua version selection
3232
- `send` - Enable `Send+Sync` support
3333
- `vendored` - Use vendored Lua
3434

‎src/bytes.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::ops::{Deref, DerefMut};
22

33
use bytes::Bytes;
44
use mlua::{
5-
BorrowedBytes, Error, FromLua, Lua, MetaMethod, Result, String as LuaString, Table, UserData,
6-
UserDataMethods, UserDataRegistry, Value,
5+
BorrowedBytes, Error, FromLua, Lua, LuaString, MetaMethod, Result, Table, UserData, UserDataMethods,
6+
UserDataRegistry, Value,
77
};
88

99
/// A Lua userdata wrapper around [`Bytes`].
@@ -85,7 +85,7 @@ impl StringOrBytes {
8585

8686
enum AsBytesRefImpl<'a> {
8787
Ref(&'a [u8]),
88-
Lua(BorrowedBytes<'a>),
88+
Lua(BorrowedBytes),
8989
}
9090

9191
impl Deref for AsBytesRefImpl<'_> {

‎src/http/body.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,16 @@ impl UserData for LuaBody {
242242
// Consumes the body if it is not buffered, returns a function that can be
243243
// called to get the next chunk of data
244244
registry.add_method_mut("reader", |lua, this, ()| {
245-
use std::cell::RefCell;
246-
use std::rc::Rc;
245+
use std::sync::Arc;
246+
247+
use tokio::sync::Mutex;
247248

248249
let body_stream = this.consume_if_unbuffered().into_data_stream();
249-
let body_stream = Rc::new(RefCell::new(body_stream));
250+
let body_stream = Arc::new(Mutex::new(body_stream));
250251
lua.create_async_function(move |lua, ()| {
251252
let body_stream = body_stream.clone();
252-
#[allow(clippy::await_holding_refcell_ref)]
253253
async move {
254-
let mut body_stream = lua_try!(body_stream.try_borrow_mut());
254+
let mut body_stream = lua_try!(body_stream.try_lock());
255255
match body_stream.next().await {
256256
Some(Ok(data)) => {
257257
let data = lua.create_any_userdata(data)?;

‎src/http/headers.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use http::header::{HeaderMap, HeaderName, HeaderValue};
22
use mlua::{
3-
Either, ExternalError, ExternalResult, FromLua, Lua, MetaMethod, Result, String as LuaString, Table,
4-
UserData, UserDataMethods, Value,
3+
Either, ExternalError, ExternalResult, FromLua, Lua, LuaString, MetaMethod, Result, Table, UserData,
4+
UserDataMethods, Value,
55
};
66

77
/// A Lua userdata wrapper around [`http::HeaderMap`].

‎src/http/method.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use mlua::{ExternalResult, FromLua, Lua, Result, String as LuaString, Value};
1+
use mlua::{ExternalResult, FromLua, Lua, LuaString, Result, Value};
22

33
/// A Lua wrapper around [`http::Method`].
44
#[derive(Clone, Default, Debug)]

‎src/http/request.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use http::request::{Parts, Request};
44
use http_body_util::Either as EitherBody;
55
use hyper::body::Incoming;
66
use mlua::{
7-
AnyUserData, Error, FromLua, Lua, MetaMethod, Result, String as LuaString, Table, UserData,
8-
UserDataMethods, Value,
7+
AnyUserData, Error, FromLua, Lua, LuaString, MetaMethod, Result, Table, UserData, UserDataMethods, Value,
98
};
109

1110
use crate::http::{LuaBody, LuaHeaderMapExt, LuaHeaders, LuaMethod};

‎src/http/response.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use http::response::{Parts, Response};
66
use http_body_util::{BodyExt, Either as EitherBody};
77
use hyper_util::client::legacy::connect::HttpInfo;
88
use mlua::{
9-
AnyUserData, ExternalResult, FromLua, Lua, MetaMethod, Result, String as LuaString, UserData,
10-
UserDataMethods, Value,
9+
AnyUserData, ExternalResult, FromLua, Lua, LuaString, MetaMethod, Result, UserData, UserDataMethods,
10+
Value,
1111
};
1212

1313
use super::headers::LuaHeaderMapExt;

‎src/json.rs‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::result::Result as StdResult;
22
use std::sync::Arc;
33

4+
use mlua::serde::SerializeOptions;
45
use mlua::{
56
AnyUserData, Error as LuaError, Function, Integer as LuaInteger, IntoLuaMulti, Lua, LuaSerdeExt,
6-
MetaMethod, MultiValue, Result, SerializeOptions, String as LuaString, Table, UserData, UserDataMethods,
7-
UserDataRefMut, Value,
7+
LuaString, MetaMethod, MultiValue, Result, Table, UserData, UserDataMethods, UserDataRefMut, Value,
88
};
99
use ouroboros::self_referencing;
1010
use serde::{Serialize, Serializer};
@@ -18,6 +18,9 @@ pub(crate) struct JsonObject {
1818
current: *const serde_json::Value,
1919
}
2020

21+
unsafe impl Send for JsonObject {}
22+
unsafe impl Sync for JsonObject {}
23+
2124
impl Serialize for JsonObject {
2225
fn serialize<S: Serializer>(&self, serializer: S) -> StdResult<S::Ok, S::Error> {
2326
self.current().serialize(serializer)
@@ -68,11 +71,7 @@ impl JsonObject {
6871
} else if let Some(n) = n.as_f64() {
6972
Ok(Value::Number(n))
7073
} else {
71-
Err(LuaError::ToLuaConversionError {
72-
from: "number".to_string(),
73-
to: "integer or float",
74-
message: Some("number is too big to fit in a Lua integer".to_owned()),
75-
})
74+
Err(LuaError::runtime("number is too big to fit in a Lua integer"))
7675
}
7776
}
7877
serde_json::Value::String(s) => Ok(Value::String(lua.create_string(s)?)),

0 commit comments

Comments
 (0)