auto-formatting
This commit is contained in:
parent
8a6161b16f
commit
f51a822738
|
@ -51,4 +51,3 @@ macro_rules! lua_assert {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
src/tests.rs
29
src/tests.rs
|
@ -22,13 +22,14 @@ fn test_load_debug() {
|
||||||
lua.load_debug();
|
lua.load_debug();
|
||||||
}
|
}
|
||||||
match lua.eval("debug", None).unwrap() {
|
match lua.eval("debug", None).unwrap() {
|
||||||
Value::Table(_) => {},
|
Value::Table(_) => {}
|
||||||
val => {
|
val => panic!("Expected table for debug library, got {:#?}", val),
|
||||||
panic!("Expected table for debug library, got {:#?}", val)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let traceback_output = lua.eval::<String>("debug.traceback()", None).unwrap();
|
let traceback_output = lua.eval::<String>("debug.traceback()", None).unwrap();
|
||||||
assert_eq!(traceback_output.split("\n").next(), "stack traceback:".into());
|
assert_eq!(
|
||||||
|
traceback_output.split("\n").next(),
|
||||||
|
"stack traceback:".into()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -553,8 +554,16 @@ fn test_pcall_xpcall() {
|
||||||
assert!(lua.exec::<()>("xpcall(function() end)", None).is_err());
|
assert!(lua.exec::<()>("xpcall(function() end)", None).is_err());
|
||||||
|
|
||||||
// Make sure that the return values from are correct on success
|
// Make sure that the return values from are correct on success
|
||||||
assert_eq!(lua.eval::<(bool, String)>("pcall(function(p) return p end, 'foo')", None).unwrap(), (true, "foo".to_owned()));
|
assert_eq!(
|
||||||
assert_eq!(lua.eval::<(bool, String)>("xpcall(function(p) return p end, print, 'foo')", None).unwrap(), (true, "foo".to_owned()));
|
lua.eval::<(bool, String)>("pcall(function(p) return p end, 'foo')", None)
|
||||||
|
.unwrap(),
|
||||||
|
(true, "foo".to_owned())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
lua.eval::<(bool, String)>("xpcall(function(p) return p end, print, 'foo')", None)
|
||||||
|
.unwrap(),
|
||||||
|
(true, "foo".to_owned())
|
||||||
|
);
|
||||||
|
|
||||||
// Make sure that the return values are correct on errors, and that error handling works
|
// Make sure that the return values are correct on errors, and that error handling works
|
||||||
|
|
||||||
|
@ -633,10 +642,12 @@ fn test_recursive_callback_panic() {
|
||||||
fn test_set_metatable_nil() {
|
fn test_set_metatable_nil() {
|
||||||
let lua = Lua::new();
|
let lua = Lua::new();
|
||||||
lua.exec::<()>(
|
lua.exec::<()>(
|
||||||
r#"
|
r#"
|
||||||
a = {}
|
a = {}
|
||||||
setmetatable(a, nil)
|
setmetatable(a, nil)
|
||||||
"#, None).unwrap();
|
"#,
|
||||||
|
None,
|
||||||
|
).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Need to use compiletest-rs or similar to make sure these don't compile.
|
// TODO: Need to use compiletest-rs or similar to make sure these don't compile.
|
||||||
|
|
|
@ -184,16 +184,18 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> {
|
||||||
R: ToLuaMulti<'lua>,
|
R: ToLuaMulti<'lua>,
|
||||||
M: 'static + for<'a> FnMut(&'lua Lua, &'a T, A) -> Result<R>,
|
M: 'static + for<'a> FnMut(&'lua Lua, &'a T, A) -> Result<R>,
|
||||||
{
|
{
|
||||||
Box::new(move |lua, mut args| if let Some(front) = args.pop_front() {
|
Box::new(move |lua, mut args| {
|
||||||
let userdata = AnyUserData::from_lua(front, lua)?;
|
if let Some(front) = args.pop_front() {
|
||||||
let userdata = userdata.borrow::<T>()?;
|
let userdata = AnyUserData::from_lua(front, lua)?;
|
||||||
method(lua, &userdata, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
|
let userdata = userdata.borrow::<T>()?;
|
||||||
} else {
|
method(lua, &userdata, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
|
||||||
Err(Error::FromLuaConversionError {
|
} else {
|
||||||
from: "missing argument",
|
Err(Error::FromLuaConversionError {
|
||||||
to: "userdata",
|
from: "missing argument",
|
||||||
message: None,
|
to: "userdata",
|
||||||
})
|
message: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,16 +205,18 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> {
|
||||||
R: ToLuaMulti<'lua>,
|
R: ToLuaMulti<'lua>,
|
||||||
M: 'static + for<'a> FnMut(&'lua Lua, &'a mut T, A) -> Result<R>,
|
M: 'static + for<'a> FnMut(&'lua Lua, &'a mut T, A) -> Result<R>,
|
||||||
{
|
{
|
||||||
Box::new(move |lua, mut args| if let Some(front) = args.pop_front() {
|
Box::new(move |lua, mut args| {
|
||||||
let userdata = AnyUserData::from_lua(front, lua)?;
|
if let Some(front) = args.pop_front() {
|
||||||
let mut userdata = userdata.borrow_mut::<T>()?;
|
let userdata = AnyUserData::from_lua(front, lua)?;
|
||||||
method(lua, &mut userdata, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
|
let mut userdata = userdata.borrow_mut::<T>()?;
|
||||||
} else {
|
method(lua, &mut userdata, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
|
||||||
Err(Error::FromLuaConversionError {
|
} else {
|
||||||
from: "missing argument",
|
Err(Error::FromLuaConversionError {
|
||||||
to: "userdata",
|
from: "missing argument",
|
||||||
message: None,
|
to: "userdata",
|
||||||
})
|
message: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue