Skip to content

Commit a4c8b20

Browse files
committed
impl IntoLuaMulti for &MultiValue
1 parent 6e353d6 commit a4c8b20

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/multi.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,23 @@ impl IntoLuaMulti for MultiValue {
204204
}
205205
}
206206

207+
impl IntoLuaMulti for &MultiValue {
208+
#[inline]
209+
fn into_lua_multi(self, _: &Lua) -> Result<MultiValue> {
210+
Ok(self.clone())
211+
}
212+
213+
#[inline]
214+
unsafe fn push_into_stack_multi(self, lua: &RawLua) -> Result<c_int> {
215+
let nresults = self.len() as i32;
216+
check_stack(lua.state(), nresults + 1)?;
217+
for value in &self.0 {
218+
lua.push_value(value)?;
219+
}
220+
Ok(nresults)
221+
}
222+
}
223+
207224
impl FromLuaMulti for MultiValue {
208225
#[inline]
209226
fn from_lua_multi(values: MultiValue, _: &Lua) -> Result<Self> {

tests/multi.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ fn test_multivalue() {
7272
let _multi2 = MultiValue::from_vec(vec);
7373
}
7474

75+
#[test]
76+
fn test_multivalue_by_ref() -> Result<()> {
77+
let lua = Lua::new();
78+
let multi = MultiValue::from_vec(vec![
79+
Value::Integer(3),
80+
Value::String(lua.create_string("hello")?),
81+
Value::Boolean(true),
82+
]);
83+
84+
let f = lua.create_function(|_, (i, s, b): (i32, String, bool)| {
85+
assert_eq!(i, 3);
86+
assert_eq!(s.to_str()?, "hello");
87+
assert_eq!(b, true);
88+
Ok(())
89+
})?;
90+
f.call::<()>(&multi)?;
91+
92+
Ok(())
93+
}
94+
7595
#[test]
7696
fn test_variadic() {
7797
let mut var = Variadic::with_capacity(3);

0 commit comments

Comments
 (0)