summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/macros.rs1
-rw-r--r--src/tests.rs29
-rw-r--r--src/userdata.rs44
3 files changed, 44 insertions, 30 deletions
diff --git a/src/macros.rs b/src/macros.rs
index 13130ac..517db21 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -51,4 +51,3 @@ macro_rules! lua_assert {
}
};
}
-
diff --git a/src/tests.rs b/src/tests.rs
index e83b3ba..bd0f94f 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -22,13 +22,14 @@ fn test_load_debug() {
lua.load_debug();
}
match lua.eval("debug", None).unwrap() {
- Value::Table(_) => {},
- val => {
- panic!("Expected table for debug library, got {:#?}", val)
- }
+ Value::Table(_) => {}
+ val => panic!("Expected table for debug library, got {:#?}", val),
}
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]
@@ -553,8 +554,16 @@ fn test_pcall_xpcall() {
assert!(lua.exec::<()>("xpcall(function() end)", None).is_err());
// 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!(lua.eval::<(bool, String)>("xpcall(function(p) return p end, print, 'foo')", None).unwrap(), (true, "foo".to_owned()));
+ assert_eq!(
+ 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
@@ -633,10 +642,12 @@ fn test_recursive_callback_panic() {
fn test_set_metatable_nil() {
let lua = Lua::new();
lua.exec::<()>(
- r#"
+ r#"
a = {}
setmetatable(a, nil)
- "#, None).unwrap();
+ "#,
+ None,
+ ).unwrap();
}
// TODO: Need to use compiletest-rs or similar to make sure these don't compile.
diff --git a/src/userdata.rs b/src/userdata.rs
index 8d52425..928405d 100644
--- a/src/userdata.rs
+++ b/src/userdata.rs
@@ -184,16 +184,18 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> {
R: ToLuaMulti<'lua>,
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() {
- let userdata = AnyUserData::from_lua(front, lua)?;
- let userdata = userdata.borrow::<T>()?;
- method(lua, &userdata, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
- } else {
- Err(Error::FromLuaConversionError {
- from: "missing argument",
- to: "userdata",
- message: None,
- })
+ Box::new(move |lua, mut args| {
+ if let Some(front) = args.pop_front() {
+ let userdata = AnyUserData::from_lua(front, lua)?;
+ let userdata = userdata.borrow::<T>()?;
+ method(lua, &userdata, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
+ } else {
+ Err(Error::FromLuaConversionError {
+ from: "missing argument",
+ to: "userdata",
+ message: None,
+ })
+ }
})
}
@@ -203,16 +205,18 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> {
R: ToLuaMulti<'lua>,
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() {
- let userdata = AnyUserData::from_lua(front, lua)?;
- let mut userdata = userdata.borrow_mut::<T>()?;
- method(lua, &mut userdata, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
- } else {
- Err(Error::FromLuaConversionError {
- from: "missing argument",
- to: "userdata",
- message: None,
- })
+ Box::new(move |lua, mut args| {
+ if let Some(front) = args.pop_front() {
+ let userdata = AnyUserData::from_lua(front, lua)?;
+ let mut userdata = userdata.borrow_mut::<T>()?;
+ method(lua, &mut userdata, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
+ } else {
+ Err(Error::FromLuaConversionError {
+ from: "missing argument",
+ to: "userdata",
+ message: None,
+ })
+ }
})
}
}