summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benches/benchmark.rs33
-rw-r--r--src/conversion.rs16
-rw-r--r--src/ffi.rs2
-rw-r--r--src/function.rs8
-rw-r--r--src/lib.rs22
-rw-r--r--src/lua.rs30
-rw-r--r--src/macros.rs7
-rw-r--r--src/multi.rs4
-rw-r--r--src/prelude.rs19
-rw-r--r--src/scope.rs20
-rw-r--r--src/string.rs4
-rw-r--r--src/table.rs4
-rw-r--r--src/tests/mod.rs156
-rw-r--r--src/tests/thread.rs42
-rw-r--r--src/tests/userdata.rs10
-rw-r--r--src/thread.rs4
-rw-r--r--src/types.rs6
-rw-r--r--src/userdata.rs11
-rw-r--r--src/util.rs8
-rw-r--r--src/value.rs8
20 files changed, 225 insertions, 189 deletions
diff --git a/benches/benchmark.rs b/benches/benchmark.rs
index 9a1f083..a6cb852 100644
--- a/benches/benchmark.rs
+++ b/benches/benchmark.rs
@@ -58,14 +58,15 @@ fn call_add_function(c: &mut Criterion) {
|| {
let lua = Lua::new();
let f = {
- let f: LuaFunction = lua.eval(
- r#"
+ let f: LuaFunction =
+ lua.eval(
+ r#"
function(a, b, c)
return a + b + c
end
"#,
- None,
- ).unwrap();
+ None,
+ ).unwrap();
lua.create_registry_value(f).unwrap()
};
(lua, f)
@@ -89,20 +90,21 @@ fn call_add_callback(c: &mut Criterion) {
|| {
let lua = Lua::new();
let f = {
- let c: LuaFunction = lua.create_function(|_, (a, b, c): (i64, i64, i64)| {
- Ok(a + b + c)
- }).unwrap();
+ let c: LuaFunction = lua
+ .create_function(|_, (a, b, c): (i64, i64, i64)| Ok(a + b + c))
+ .unwrap();
lua.globals().set("callback", c).unwrap();
- let f: LuaFunction = lua.eval(
- r#"
+ let f: LuaFunction =
+ lua.eval(
+ r#"
function()
for i = 1,10 do
callback(i, i, i)
end
end
"#,
- None,
- ).unwrap();
+ None,
+ ).unwrap();
lua.create_registry_value(f).unwrap()
};
(lua, f)
@@ -129,16 +131,17 @@ fn call_append_callback(c: &mut Criterion) {
Ok(format!("{}{}", a.to_str()?, b.to_str()?))
}).unwrap();
lua.globals().set("callback", c).unwrap();
- let f: LuaFunction = lua.eval(
- r#"
+ let f: LuaFunction =
+ lua.eval(
+ r#"
function()
for _ = 1,10 do
callback("a", "b")
end
end
"#,
- None,
- ).unwrap();
+ None,
+ ).unwrap();
lua.create_registry_value(f).unwrap()
};
(lua, f)
diff --git a/src/conversion.rs b/src/conversion.rs
index e643e93..b65eb4f 100644
--- a/src/conversion.rs
+++ b/src/conversion.rs
@@ -3,14 +3,14 @@ use std::hash::{BuildHasher, Hash};
use std::string::String as StdString;
use error::{Error, Result};
-use types::{Integer, LightUserData, Number};
+use function::Function;
+use lua::Lua;
use string::String;
use table::Table;
-use userdata::{AnyUserData, UserData};
-use function::Function;
use thread::Thread;
+use types::{Integer, LightUserData, Number};
+use userdata::{AnyUserData, UserData};
use value::{FromLua, Nil, ToLua, Value};
-use lua::Lua;
impl<'lua> ToLua<'lua> for Value<'lua> {
fn to_lua(self, _: &'lua Lua) -> Result<Value<'lua>> {
@@ -204,7 +204,7 @@ impl<'lua, 'a> ToLua<'lua> for &'a str {
}
macro_rules! lua_convert_int {
- ($x: ty) => {
+ ($x:ty) => {
impl<'lua> ToLua<'lua> for $x {
fn to_lua(self, _: &'lua Lua) -> Result<Value<'lua>> {
Ok(Value::Integer(self as Integer))
@@ -216,7 +216,7 @@ macro_rules! lua_convert_int {
Ok(lua.coerce_integer(value)? as $x)
}
}
- }
+ };
}
lua_convert_int!(i8);
@@ -231,7 +231,7 @@ lua_convert_int!(isize);
lua_convert_int!(usize);
macro_rules! lua_convert_float {
- ($x: ty) => {
+ ($x:ty) => {
impl<'lua> ToLua<'lua> for $x {
fn to_lua(self, _: &'lua Lua) -> Result<Value<'lua>> {
Ok(Value::Number(self as Number))
@@ -243,7 +243,7 @@ macro_rules! lua_convert_float {
Ok(lua.coerce_number(value)? as $x)
}
}
- }
+ };
}
lua_convert_float!(f32);
diff --git a/src/ffi.rs b/src/ffi.rs
index f72045c..69e432b 100644
--- a/src/ffi.rs
+++ b/src/ffi.rs
@@ -2,9 +2,9 @@
#![allow(non_snake_case)]
#![allow(unused)]
-use std::ptr;
use std::mem;
use std::os::raw::{c_char, c_double, c_int, c_longlong, c_uchar, c_void};
+use std::ptr;
pub type lua_Integer = c_longlong;
pub type lua_Number = c_double;
diff --git a/src/function.rs b/src/function.rs
index baee0f7..0b10ed8 100644
--- a/src/function.rs
+++ b/src/function.rs
@@ -1,10 +1,12 @@
-use std::ptr;
use std::os::raw::c_int;
+use std::ptr;
-use ffi;
use error::{Error, Result};
-use util::{assert_stack, check_stack, error_traceback, pop_error, protect_lua_closure, StackGuard};
+use ffi;
use types::LuaRef;
+use util::{
+ assert_stack, check_stack, error_traceback, pop_error, protect_lua_closure, StackGuard,
+};
use value::{FromLuaMulti, MultiValue, ToLuaMulti};
/// Handle to an internal Lua function.
diff --git a/src/lib.rs b/src/lib.rs
index ec76b8c..d7106cd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -44,36 +44,36 @@
extern crate failure;
extern crate libc;
-mod ffi;
mod error;
+mod ffi;
#[macro_use]
mod macros;
-mod util;
-mod value;
-mod types;
-mod lua;
mod conversion;
+mod function;
+mod lua;
mod multi;
+mod scope;
mod string;
mod table;
-mod function;
mod thread;
+mod types;
mod userdata;
-mod scope;
+mod util;
+mod value;
#[cfg(test)]
mod tests;
pub use error::{Error, ExternalError, ExternalResult, Result};
-pub use types::{Integer, LightUserData, Number, RegistryKey};
+pub use function::Function;
+pub use lua::Lua;
pub use multi::Variadic;
+pub use scope::Scope;
pub use string::String;
pub use table::{Table, TablePairs, TableSequence};
-pub use function::Function;
pub use thread::{Thread, ThreadStatus};
+pub use types::{Integer, LightUserData, Number, RegistryKey};
pub use userdata::{AnyUserData, MetaMethod, UserData, UserDataMethods};
pub use value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti, Value};
-pub use lua::Lua;
-pub use scope::Scope;
pub mod prelude;
diff --git a/src/lua.rs b/src/lua.rs
index a2317c5..4284c8c 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -1,28 +1,29 @@
-use std::{mem, ptr, str};
-use std::sync::{Arc, Mutex};
+use std::any::TypeId;
use std::cell::{RefCell, UnsafeCell};
+use std::collections::HashMap;
use std::ffi::CString;
-use std::any::TypeId;
use std::marker::PhantomData;
-use std::collections::HashMap;
use std::os::raw::{c_char, c_int, c_void};
+use std::sync::{Arc, Mutex};
+use std::{mem, ptr, str};
use libc;
-use ffi;
use error::{Error, Result};
-use util::{assert_stack, callback_error, check_stack, gc_guard, get_userdata, get_wrapped_error,
- init_error_metatables, main_state, pop_error, protect_lua, protect_lua_closure,
- push_string, push_userdata, push_wrapped_error, safe_pcall, safe_xpcall,
- userdata_destructor, StackGuard};
-use value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti, Value};
-use types::{Callback, Integer, LightUserData, LuaRef, Number, RegistryKey};
+use ffi;
+use function::Function;
+use scope::Scope;
use string::String;
use table::Table;
-use function::Function;
use thread::Thread;
+use types::{Callback, Integer, LightUserData, LuaRef, Number, RegistryKey};
use userdata::{AnyUserData, MetaMethod, UserData, UserDataMethods};
-use scope::Scope;
+use util::{
+ assert_stack, callback_error, check_stack, gc_guard, get_userdata, get_wrapped_error,
+ init_error_metatables, main_state, pop_error, protect_lua, protect_lua_closure, push_string,
+ push_userdata, push_wrapped_error, safe_pcall, safe_xpcall, userdata_destructor, StackGuard,
+};
+use value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti, Value};
/// Top level Lua struct which holds the Lua state itself.
pub struct Lua {
@@ -285,7 +286,8 @@ impl Lua {
{
let func = RefCell::new(func);
self.create_function(move |lua, args| {
- (&mut *func.try_borrow_mut()
+ (&mut *func
+ .try_borrow_mut()
.map_err(|_| Error::RecursiveMutCallback)?)(lua, args)
})
}
diff --git a/src/macros.rs b/src/macros.rs
index 233495f..b37722a 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -1,7 +1,8 @@
macro_rules! cstr {
- ($s:expr) => (
- concat!($s, "\0") as *const str as *const [::std::os::raw::c_char] as *const ::std::os::raw::c_char
- );
+ ($s:expr) => {
+ concat!($s, "\0") as *const str as *const [::std::os::raw::c_char]
+ as *const ::std::os::raw::c_char
+ };
}
macro_rules! abort {
diff --git a/src/multi.rs b/src/multi.rs
index 4d5a25a..20f5000 100644
--- a/src/multi.rs
+++ b/src/multi.rs
@@ -1,10 +1,10 @@
-use std::ops::{Deref, DerefMut};
use std::iter::FromIterator;
+use std::ops::{Deref, DerefMut};
use std::result::Result as StdResult;
use error::Result;
-use value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti};
use lua::Lua;
+use value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti};
/// Result is convertible to `MultiValue` following the common Lua idiom of returning the result
/// on success, or in the case of an error, returning `nil` and an error message.
diff --git a/src/prelude.rs b/src/prelude.rs
index 6e3059c..8d25741 100644
--- a/src/prelude.rs
+++ b/src/prelude.rs
@@ -1,11 +1,12 @@
//! Re-exports most types with an extra `Lua*` prefix to prevent name clashes.
-pub use {AnyUserData as LuaAnyUserData, Error as LuaError, ExternalError as LuaExternalError,
- ExternalResult as LuaExternalResult, FromLua, FromLuaMulti, Function as LuaFunction,
- Integer as LuaInteger, LightUserData as LuaLightUserData, Lua,
- MetaMethod as LuaMetaMethod, MultiValue as LuaMultiValue, Nil as LuaNil,
- Number as LuaNumber, RegistryKey as LuaRegistryKey, Result as LuaResult,
- Scope as LuaScope, String as LuaString, Table as LuaTable, TablePairs as LuaTablePairs,
- TableSequence as LuaTableSequence, Thread as LuaThread, ThreadStatus as LuaThreadStatus,
- ToLua, ToLuaMulti, UserData as LuaUserData, UserDataMethods as LuaUserDataMethods,
- Value as LuaValue};
+pub use {
+ AnyUserData as LuaAnyUserData, Error as LuaError, ExternalError as LuaExternalError,
+ ExternalResult as LuaExternalResult, FromLua, FromLuaMulti, Function as LuaFunction,
+ Integer as LuaInteger, LightUserData as LuaLightUserData, Lua, MetaMethod as LuaMetaMethod,
+ MultiValue as LuaMultiValue, Nil as LuaNil, Number as LuaNumber, RegistryKey as LuaRegistryKey,
+ Result as LuaResult, Scope as LuaScope, String as LuaString, Table as LuaTable,
+ TablePairs as LuaTablePairs, TableSequence as LuaTableSequence, Thread as LuaThread,
+ ThreadStatus as LuaThreadStatus, ToLua, ToLuaMulti, UserData as LuaUserData,
+ UserDataMethods as LuaUserDataMethods, Value as LuaValue,
+};
diff --git a/src/scope.rs b/src/scope.rs
index 7a324d4..476b5c1 100644
--- a/src/scope.rs
+++ b/src/scope.rs
@@ -1,16 +1,16 @@
-use std::mem;
-use std::cell::RefCell;
use std::any::Any;
+use std::cell::RefCell;
use std::marker::PhantomData;
+use std::mem;
-use ffi;
use error::{Error, Result};
-use util::{assert_stack, take_userdata, StackGuard};
-use value::{FromLuaMulti, ToLuaMulti};
-use types::Callback;
-use lua::Lua;
+use ffi;
use function::Function;
+use lua::Lua;
+use types::Callback;
use userdata::{AnyUserData, UserData};
+use util::{assert_stack, take_userdata, StackGuard};
+use value::{FromLuaMulti, ToLuaMulti};
/// Constructed by the [`Lua::scope`] method, allows temporarily passing to Lua userdata that is
/// !Send, and callbacks that are !Send and not 'static.
@@ -109,7 +109,8 @@ impl<'scope> Scope<'scope> {
{
let func = RefCell::new(func);
self.create_function(move |lua, args| {
- (&mut *func.try_borrow_mut()
+ (&mut *func
+ .try_borrow_mut()
.map_err(|_| Error::RecursiveMutCallback)?)(lua, args)
})
}
@@ -148,7 +149,8 @@ impl<'scope> Drop for Scope<'scope> {
// userdata type into two phases. This is so that, in the event a userdata drop panics, we
// can be sure that all of the userdata in Lua is actually invalidated.
- let to_drop = self.destructors
+ let to_drop = self
+ .destructors
.get_mut()
.drain(..)
.map(|destructor| destructor())
diff --git a/src/string.rs b/src/string.rs
index 0f6ded1..164733b 100644
--- a/src/string.rs
+++ b/src/string.rs
@@ -1,9 +1,9 @@
use std::{slice, str};
-use ffi;
use error::{Error, Result};
-use util::{assert_stack, StackGuard};
+use ffi;
use types::LuaRef;
+use util::{assert_stack, StackGuard};
/// Handle to an internal Lua string.
///
diff --git a/src/table.rs b/src/table.rs
index 2ab4ab7..a32007d 100644
--- a/src/table.rs
+++ b/src/table.rs
@@ -1,10 +1,10 @@
use std::marker::PhantomData;
use std::os::raw::c_int;
-use ffi;
use error::Result;
-use util::{assert_stack, protect_lua, protect_lua_closure, StackGuard};
+use ffi;
use types::{Integer, LuaRef};
+use util::{assert_stack, protect_lua, protect_lua_closure, StackGuard};
use value::{FromLua, Nil, ToLua, Value};
/// Handle to an internal Lua table.
diff --git a/src/tests/mod.rs b/src/tests/mod.rs
index cffc462..deed3bd 100644
--- a/src/tests/mod.rs
+++ b/src/tests/mod.rs
@@ -5,15 +5,17 @@ mod thread;
mod types;
mod userdata;
-use std::{error, fmt};
+use std::cell::Cell;
use std::iter::FromIterator;
+use std::panic::catch_unwind;
use std::rc::Rc;
-use std::cell::Cell;
use std::sync::Arc;
-use std::panic::catch_unwind;
+use std::{error, fmt};
-use {Error, ExternalError, Function, Lua, Nil, Result, String, Table, UserData, UserDataMethods,
- Value, Variadic};
+use {
+ Error, ExternalError, Function, Lua, Nil, Result, String, Table, UserData, UserDataMethods,
+ Value, Variadic,
+};
#[test]
fn test_load() {
@@ -51,8 +53,9 @@ fn test_exec() {
).unwrap();
assert_eq!(globals.get::<_, String>("res").unwrap(), "foobar");
- let module: Table = lua.exec(
- r#"
+ let module: Table =
+ lua.exec(
+ r#"
local module = {}
function module.func()
@@ -61,8 +64,8 @@ fn test_exec() {
return module
"#,
- None,
- ).unwrap();
+ None,
+ ).unwrap();
assert!(module.contains_key("func").unwrap());
assert_eq!(
module
@@ -214,9 +217,9 @@ fn test_error() {
None,
).unwrap();
- let rust_error_function = lua.create_function(|_, ()| -> Result<()> {
- Err(TestError.to_lua_err())
- }).unwrap();
+ let rust_error_function = lua
+ .create_function(|_, ()| -> Result<()> { Err(TestError.to_lua_err()) })
+ .unwrap();
globals
.set("rust_error_function", rust_error_function)
.unwrap();
@@ -281,9 +284,9 @@ fn test_error() {
"#,
None,
)?;
- let rust_panic_function = lua.create_function(|_, ()| -> Result<()> {
- panic!("test_panic")
- }).unwrap();
+ let rust_panic_function = lua
+ .create_function(|_, ()| -> Result<()> { panic!("test_panic") })
+ .unwrap();
globals.set("rust_panic_function", rust_panic_function)?;
let rust_panic = globals.get::<_, Function>("rust_panic")?;
@@ -307,9 +310,9 @@ fn test_error() {
"#,
None,
)?;
- let rust_panic_function = lua.create_function(|_, ()| -> Result<()> {
- panic!("test_panic")
- }).unwrap();
+ let rust_panic_function = lua
+ .create_function(|_, ()| -> Result<()> { panic!("test_panic") })
+ .unwrap();
globals.set("rust_panic_function", rust_panic_function)?;
let rust_panic = globals.get::<_, Function>("rust_panic")?;
@@ -327,12 +330,14 @@ fn test_result_conversions() {
let lua = Lua::new();
let globals = lua.globals();
- let err = lua.create_function(|_, ()| {
- Ok(Err::<String, _>(
- format_err!("only through failure can we succeed").to_lua_err(),
- ))
- }).unwrap();
- let ok = lua.create_function(|_, ()| Ok(Ok::<_, Error>("!".to_owned())))
+ let err =
+ lua.create_function(|_, ()| {
+ Ok(Err::<String, _>(
+ format_err!("only through failure can we succeed").to_lua_err(),
+ ))
+ }).unwrap();
+ let ok = lua
+ .create_function(|_, ()| Ok(Ok::<_, Error>("!".to_owned())))
.unwrap();
globals.set("err", err).unwrap();
@@ -389,12 +394,14 @@ fn test_pcall_xpcall() {
// Make sure that the return values from are correct on success
- let (r, e) = lua.eval::<(bool, String)>("pcall(function(p) return p end, 'foo')", None)
+ let (r, e) = lua
+ .eval::<(bool, String)>("pcall(function(p) return p end, 'foo')", None)
.unwrap();
assert!(r);
assert_eq!(e, "foo");
- let (r, e) = lua.eval::<(bool, String)>("xpcall(function(p) return p end, print, 'foo')", None)
+ let (r, e) = lua
+ .eval::<(bool, String)>("xpcall(function(p) return p end, print, 'foo')", None)
.unwrap();
assert!(r);
assert_eq!(e, "foo");
@@ -444,23 +451,26 @@ fn test_recursive_mut_callback_error() {
let lua = Lua::new();
let mut v = Some(Box::new(123));
- let f = lua.create_function_mut::<_, (), _>(move |lua, mutate: bool| {
- if mutate {
- v = None;
- } else {
- // Produce a mutable reference
- let r = v.as_mut().unwrap();
- // Whoops, this will recurse into the function and produce another mutable reference!
- lua.globals().get::<_, Function>("f")?.call::<_, ()>(true)?;
- println!("Should not get here, mutable aliasing has occurred!");
- println!("value at {:p}", r as *mut _);
- println!("value is {}", r);
- }
-
- Ok(())
- }).unwrap();
+ let f = lua
+ .create_function_mut::<_, (), _>(move |lua, mutate: bool| {
+ if mutate {
+ v = None;
+ } else {
+ // Produce a mutable reference
+ let r = v.as_mut().unwrap();
+ // Whoops, this will recurse into the function and produce another mutable reference!
+ lua.globals().get::<_, Function>("f")?.call::<_, ()>(true)?;
+ println!("Should not get here, mutable aliasing has occurred!");
+ println!("value at {:p}", r as *mut _);
+ println!("value is {}", r);
+ }
+
+ Ok(())
+ })
+ .unwrap();
lua.globals().set("f", f).unwrap();
- match lua.globals()
+ match lua
+ .globals()
.get::<_, Function>("f")
.unwrap()
.call::<_, ()>(false)
@@ -516,10 +526,11 @@ fn test_named_registry_value() {
let lua = Lua::new();
lua.set_named_registry_value::<i32>("test", 42).unwrap();
- let f = lua.create_function(move |lua, ()| {
- assert_eq!(lua.named_registry_value::<i32>("test")?, 42);
- Ok(())
- }).unwrap();
+ let f =
+ lua.create_function(move |lua, ()| {
+ assert_eq!(lua.named_registry_value::<i32>("test")?, 42);
+ Ok(())
+ }).unwrap();
f.call::<_, ()>(()).unwrap();
@@ -535,15 +546,16 @@ fn test_registry_value() {
let lua = Lua::new();
let mut r = Some(lua.create_registry_value::<i32>(42).unwrap());
- let f = lua.create_function_mut(move |lua, ()| {
- if let Some(r) = r.take() {
- assert_eq!(lua.registry_value::<i32>(&r)?, 42);
- lua.remove_registry_value(r).unwrap();
- } else {
- panic!();
- }
- Ok(())
- }).unwrap();
+ let f =
+ lua.create_function_mut(move |lua, ()| {
+ if let Some(r) = r.take() {
+ assert_eq!(lua.registry_value::<i32>(&r)?, 42);
+ lua.remove_registry_value(r).unwrap();
+ } else {
+ panic!();
+ }
+ Ok(())
+ }).unwrap();
f.call::<_, ()>(()).unwrap();
}
@@ -628,7 +640,8 @@ fn scope_func() {
assert_eq!(rc.get(), 42);
assert_eq!(Rc::strong_count(&rc), 1);
- match lua.globals()
+ match lua
+ .globals()
.get::<_, Function>("bad")
.unwrap()
.call::<_, ()>(())
@@ -706,7 +719,8 @@ fn outer_lua_access() {
#[test]
fn too_many_returns() {
let lua = Lua::new();
- let f = lua.create_function(|_, ()| Ok(Variadic::from_iter(1..1000000)))
+ let f = lua
+ .create_function(|_, ()| Ok(Variadic::from_iter(1..1000000)))
.unwrap();
assert!(f.call::<_, Vec<u32>>(()).is_err());
}
@@ -729,9 +743,9 @@ fn too_many_arguments() {
fn too_many_recursions() {
let lua = Lua::new();
- let f = lua.create_function(move |lua, ()| {
- lua.globals().get::<_, Function>("f")?.call::<_, ()>(())
- }).unwrap();
+ let f = lua
+ .create_function(move |lua, ()| lua.globals().get::<_, Function>("f")?.call::<_, ()>(()))
+ .unwrap();
lua.globals().set("f", f).unwrap();
assert!(
@@ -783,14 +797,15 @@ fn large_args() {
)
.unwrap();
- let f: Function = lua.eval(
- r#"
+ let f: Function =
+ lua.eval(
+ r#"
return function(...)
return c(...)
end
"#,
- None,
- ).unwrap();
+ None,
+ ).unwrap();
assert_eq!(
f.call::<_, usize>((0..100).collect::<Variadic<usize>>())
@@ -803,12 +818,13 @@ fn large_args() {
fn large_args_ref() {
let lua = Lua::new();
- let f = lua.create_function(|_, args: Variadic<String>| {
- for i in 0..args.len() {
- assert_eq!(args[i], i.to_string());
- }
- Ok(())
- }).unwrap();
+ let f =
+ lua.create_function(|_, args: Variadic<String>| {
+ for i in 0..args.len() {
+ assert_eq!(args[i], i.to_string());
+ }
+ Ok(())
+ }).unwrap();
f.call::<_, ()>((0..100).map(|i| i.to_string()).collect::<Variadic<_>>())
.unwrap();
diff --git a/src/tests/thread.rs b/src/tests/thread.rs
index 48284d7..c9ac878 100644
--- a/src/tests/thread.rs
+++ b/src/tests/thread.rs
@@ -5,8 +5,10 @@ use {Error, Function, Lua, Result, Thread, ThreadStatus};
#[test]
fn test_thread() {
let lua = Lua::new();
- let thread = lua.create_thread(lua.eval::<Function>(
- r#"
+ let thread =
+ lua.create_thread(
+ lua.eval::<Function>(
+ r#"
function (s)
local sum = s
for i = 1,4 do
@@ -15,9 +17,9 @@ fn test_thread() {
return sum
end
"#,
- None,
- ).unwrap())
- .unwrap();
+ None,
+ ).unwrap(),
+ ).unwrap();
assert_eq!(thread.status(), ThreadStatus::Resumable);
assert_eq!(thread.resume::<_, i64>(0).unwrap(), 0);
@@ -31,17 +33,19 @@ fn test_thread() {
assert_eq!(thread.resume::<_, i64>(4).unwrap(), 10);
assert_eq!(thread.status(), ThreadStatus::Unresumable);
- let accumulate = lua.create_thread(lua.eval::<Function>(
- r#"
+ let accumulate =
+ lua.create_thread(
+ lua.eval::<Function>(
+ r#"
function (sum)
while true do
sum = sum + coroutine.yield(sum)
end
end
"#,
- None,
- ).unwrap())
- .unwrap();
+ None,
+ ).unwrap(),
+ ).unwrap();
for i in 0..4 {
accumulate.resume::<_, ()>(i).unwrap();
@@ -51,21 +55,23 @@ fn test_thread() {
assert!(accumulate.resume::<_, ()>("error").is_err());
assert_eq!(accumulate.status(), ThreadStatus::Error);
- let thread = lua.eval::<Thread>(
- r#"
+ let thread =
+ lua.eval::<Thread>(
+ r#"
coroutine.create(function ()
while true do
coroutine.yield(42)
end
end)
"#,
- None,
- ).unwrap();
+ None,
+ ).unwrap();
assert_eq!(thread.status(), ThreadStatus::Resumable);
assert_eq!(thread.resume::<_, i64>(()).unwrap(), 42);
- let thread: Thread = lua.eval(
- r#"
+ let thread: Thread =
+ lua.eval(
+ r#"
coroutine.create(function(arg)
assert(arg == 42)
local yieldarg = coroutine.yield(123)
@@ -73,8 +79,8 @@ fn test_thread() {
return 987
end)
"#,
- None,
- ).unwrap();
+ None,
+ ).unwrap();
assert_eq!(thread.resume::<_, u32>(42).unwrap(), 123);
assert_eq!(thread.resume::<_, u32>(43).unwrap(), 987);
diff --git a/src/tests/userdata.rs b/src/tests/userdata.rs
index 4a51000..56d70af 100644
--- a/src/tests/userdata.rs
+++ b/src/tests/userdata.rs
@@ -131,8 +131,9 @@ fn test_gc_userdata() {
globals.set("userdata", MyUserdata { id: 123 }).unwrap();
}
- assert!(lua.eval::<()>(
- r#"
+ assert!(
+ lua.eval::<()>(
+ r#"
local tbl = setmetatable({
userdata = userdata
}, { __gc = function(self)
@@ -145,8 +146,9 @@ fn test_gc_userdata() {
collectgarbage("collect")
hatch:access()
"#,
- None
- ).is_err());
+ None
+ ).is_err()
+ );
}
#[test]
diff --git a/src/thread.rs b/src/thread.rs
index daad7b3..6922759 100644
--- a/src/thread.rs
+++ b/src/thread.rs
@@ -1,9 +1,9 @@
use std::os::raw::c_int;
-use ffi;
use error::{Error, Result};
-use util::{assert_stack, check_stack, error_traceback, pop_error, StackGuard};
+use ffi;
use types::LuaRef;
+use util::{assert_stack, check_stack, error_traceback, pop_error, StackGuard};
use value::{FromLuaMulti, MultiValue, ToLuaMulti};
/// Status of a Lua thread (or coroutine).
diff --git a/src/types.rs b/src/types.rs
index f3f1896..300467c 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -1,11 +1,11 @@
-use std::{fmt, mem, ptr};
use std::os::raw::{c_int, c_void};
use std::sync::{Arc, Mutex};
+use std::{fmt, mem, ptr};
-use ffi;
use error::Result;
-use value::MultiValue;
+use ffi;
use lua::Lua;
+use value::MultiValue;
/// Type of Lua integer numbers.
pub type Integer = ffi::lua_Integer;
diff --git a/src/userdata.rs b/src/userdata.rs
index acedb35..6bacdae 100644
--- a/src/userdata.rs
+++ b/src/userdata.rs
@@ -1,14 +1,14 @@
use std::cell::{Ref, RefCell, RefMut};
-use std::marker::PhantomData;
use std::collections::HashMap;
+use std::marker::PhantomData;
use std::string::String as StdString;
-use ffi;
use error::{Error, Result};
-use util::{assert_stack, get_userdata, StackGuard};
+use ffi;
+use lua::Lua;
use types::{Callback, LuaRef};
+use util::{assert_stack, get_userdata, StackGuard};
use value::{FromLua, FromLuaMulti, ToLua, ToLuaMulti};
-use lua::Lua;
/// Kinds of metamethods that can be overridden.
///
@@ -403,7 +403,8 @@ impl<'lua> AnyUserData<'lua> {
/// `UserDataTypeMismatch` if the userdata is not of type `T`.
pub fn borrow_mut<T: UserData>(&self) -> Result<RefMut<T>> {
self.inspect(|cell| {
- Ok(cell.try_borrow_mut()
+ Ok(cell
+ .try_borrow_mut()
.map_err(|_| Error::UserDataBorrowMutError)?)
})
}
diff --git a/src/util.rs b/src/util.rs
index c879565..b650d9a 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,12 +1,12 @@
-use std::{mem, ptr};
-use std::sync::Arc;
-use std::ffi::CStr;
use std::any::Any;
+use std::ffi::CStr;
use std::os::raw::{c_char, c_int, c_void};
use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
+use std::sync::Arc;
+use std::{mem, ptr};
-use ffi;
use error::{Error, Result};
+use ffi;
// Checks that Lua has enough free stack space for future stack operations. On failure, this will
// panic with an internal error message.
diff --git a/src/value.rs b/src/value.rs
index 780507a..bb4433d 100644
--- a/src/value.rs
+++ b/src/value.rs
@@ -1,14 +1,14 @@
-use std::{slice, str, vec};
use std::iter::{self, FromIterator};
+use std::{slice, str, vec};
use error::{Error, Result};
-use types::{Integer, LightUserData, Number};
+use function::Function;
+use lua::Lua;
use string::String;
use table::Table;
-use function::Function;
use thread::Thread;
+use types::{Integer, LightUserData, Number};
use userdata::AnyUserData;
-use lua::Lua;
/// A dynamically typed Lua value. The `String`, `Table`, `Function`, `Thread`, and `UserData`
/// variants contain handle types into the internal Lua state. It is a logic error to mix handle