Fix a bug in Function::bind
when args and binds are empty
This leads to a Lua assertion due to using wrong stack index
This commit is contained in:
parent
d3b48cf2f3
commit
40fe937878
|
@ -198,7 +198,9 @@ impl<'lua> Function<'lua> {
|
|||
for i in 0..nbinds {
|
||||
ffi::lua_pushvalue(state, ffi::lua_upvalueindex(i + 2));
|
||||
}
|
||||
ffi::lua_rotate(state, 1, nbinds);
|
||||
if nargs > 0 {
|
||||
ffi::lua_rotate(state, 1, nbinds);
|
||||
}
|
||||
|
||||
nargs + nbinds
|
||||
}
|
||||
|
|
|
@ -42,11 +42,17 @@ fn test_bind() -> Result<()> {
|
|||
concat = concat.bind("foo")?;
|
||||
concat = concat.bind("bar")?;
|
||||
concat = concat.bind(("baz", "baf"))?;
|
||||
assert_eq!(concat.call::<_, String>(())?, "foobarbazbaf");
|
||||
assert_eq!(
|
||||
concat.call::<_, String>(("hi", "wut"))?,
|
||||
"foobarbazbafhiwut"
|
||||
);
|
||||
|
||||
let mut concat2 = globals.get::<_, Function>("concat")?;
|
||||
concat2 = concat2.bind(())?;
|
||||
assert_eq!(concat2.call::<_, String>(())?, "");
|
||||
assert_eq!(concat2.call::<_, String>(("ab", "cd"))?, "abcd");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue