format with up-to-date rustfmt
This commit is contained in:
parent
e6688e1db2
commit
2e1bdb64c0
|
@ -58,7 +58,8 @@ fn call_add_function(c: &mut Criterion) {
|
|||
|| {
|
||||
let lua = Lua::new();
|
||||
let f = {
|
||||
let f: LuaFunction = lua.eval(
|
||||
let f: LuaFunction =
|
||||
lua.eval(
|
||||
r#"
|
||||
function(a, b, c)
|
||||
return a + b + c
|
||||
|
@ -89,11 +90,12 @@ 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(
|
||||
let f: LuaFunction =
|
||||
lua.eval(
|
||||
r#"
|
||||
function()
|
||||
for i = 1,10 do
|
||||
|
@ -129,7 +131,8 @@ 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(
|
||||
let f: LuaFunction =
|
||||
lua.eval(
|
||||
r#"
|
||||
function()
|
||||
for _ = 1,10 do
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
22
src/lib.rs
22
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;
|
||||
|
|
32
src/lua.rs
32
src/lua.rs
|
@ -1,28 +1,29 @@
|
|||
use std::{mem, ptr, str};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::cell::{RefCell, UnsafeCell};
|
||||
use std::ffi::CString;
|
||||
use std::any::TypeId;
|
||||
use std::marker::PhantomData;
|
||||
use std::cell::{RefCell, UnsafeCell};
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::CString;
|
||||
use std::marker::PhantomData;
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
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};
|
||||
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,
|
||||
};
|
||||
|
|
20
src/scope.rs
20
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 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};
|
||||
use types::Callback;
|
||||
use lua::Lua;
|
||||
use function::Function;
|
||||
use userdata::{AnyUserData, UserData};
|
||||
|
||||
/// 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())
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -5,15 +5,17 @@ mod thread;
|
|||
mod types;
|
||||
mod userdata;
|
||||
|
||||
use std::{error, fmt};
|
||||
use std::iter::FromIterator;
|
||||
use std::rc::Rc;
|
||||
use std::cell::Cell;
|
||||
use std::sync::Arc;
|
||||
use std::iter::FromIterator;
|
||||
use std::panic::catch_unwind;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
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,7 +53,8 @@ fn test_exec() {
|
|||
).unwrap();
|
||||
assert_eq!(globals.get::<_, String>("res").unwrap(), "foobar");
|
||||
|
||||
let module: Table = lua.exec(
|
||||
let module: Table =
|
||||
lua.exec(
|
||||
r#"
|
||||
local 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(|_, ()| {
|
||||
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 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,7 +451,8 @@ 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| {
|
||||
let f = lua
|
||||
.create_function_mut::<_, (), _>(move |lua, mutate: bool| {
|
||||
if mutate {
|
||||
v = None;
|
||||
} else {
|
||||
|
@ -458,9 +466,11 @@ fn test_recursive_mut_callback_error() {
|
|||
}
|
||||
|
||||
Ok(())
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
lua.globals().set("f", f).unwrap();
|
||||
match lua.globals()
|
||||
match lua
|
||||
.globals()
|
||||
.get::<_, Function>("f")
|
||||
.unwrap()
|
||||
.call::<_, ()>(false)
|
||||
|
@ -516,7 +526,8 @@ 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, ()| {
|
||||
let f =
|
||||
lua.create_function(move |lua, ()| {
|
||||
assert_eq!(lua.named_registry_value::<i32>("test")?, 42);
|
||||
Ok(())
|
||||
}).unwrap();
|
||||
|
@ -535,7 +546,8 @@ 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, ()| {
|
||||
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();
|
||||
|
@ -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,7 +797,8 @@ fn large_args() {
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
let f: Function = lua.eval(
|
||||
let f: Function =
|
||||
lua.eval(
|
||||
r#"
|
||||
return function(...)
|
||||
return c(...)
|
||||
|
@ -803,7 +818,8 @@ fn large_args() {
|
|||
fn large_args_ref() {
|
||||
let lua = Lua::new();
|
||||
|
||||
let f = lua.create_function(|_, args: Variadic<String>| {
|
||||
let f =
|
||||
lua.create_function(|_, args: Variadic<String>| {
|
||||
for i in 0..args.len() {
|
||||
assert_eq!(args[i], i.to_string());
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@ use {Error, Function, Lua, Result, Thread, ThreadStatus};
|
|||
#[test]
|
||||
fn test_thread() {
|
||||
let lua = Lua::new();
|
||||
let thread = lua.create_thread(lua.eval::<Function>(
|
||||
let thread =
|
||||
lua.create_thread(
|
||||
lua.eval::<Function>(
|
||||
r#"
|
||||
function (s)
|
||||
local sum = s
|
||||
|
@ -16,8 +18,8 @@ fn test_thread() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap())
|
||||
.unwrap();
|
||||
).unwrap(),
|
||||
).unwrap();
|
||||
|
||||
assert_eq!(thread.status(), ThreadStatus::Resumable);
|
||||
assert_eq!(thread.resume::<_, i64>(0).unwrap(), 0);
|
||||
|
@ -31,7 +33,9 @@ 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>(
|
||||
let accumulate =
|
||||
lua.create_thread(
|
||||
lua.eval::<Function>(
|
||||
r#"
|
||||
function (sum)
|
||||
while true do
|
||||
|
@ -40,8 +44,8 @@ fn test_thread() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap())
|
||||
.unwrap();
|
||||
).unwrap(),
|
||||
).unwrap();
|
||||
|
||||
for i in 0..4 {
|
||||
accumulate.resume::<_, ()>(i).unwrap();
|
||||
|
@ -51,7 +55,8 @@ fn test_thread() {
|
|||
assert!(accumulate.resume::<_, ()>("error").is_err());
|
||||
assert_eq!(accumulate.status(), ThreadStatus::Error);
|
||||
|
||||
let thread = lua.eval::<Thread>(
|
||||
let thread =
|
||||
lua.eval::<Thread>(
|
||||
r#"
|
||||
coroutine.create(function ()
|
||||
while true do
|
||||
|
@ -64,7 +69,8 @@ fn test_thread() {
|
|||
assert_eq!(thread.status(), ThreadStatus::Resumable);
|
||||
assert_eq!(thread.resume::<_, i64>(()).unwrap(), 42);
|
||||
|
||||
let thread: Thread = lua.eval(
|
||||
let thread: Thread =
|
||||
lua.eval(
|
||||
r#"
|
||||
coroutine.create(function(arg)
|
||||
assert(arg == 42)
|
||||
|
|
|
@ -131,7 +131,8 @@ fn test_gc_userdata() {
|
|||
globals.set("userdata", MyUserdata { id: 123 }).unwrap();
|
||||
}
|
||||
|
||||
assert!(lua.eval::<()>(
|
||||
assert!(
|
||||
lua.eval::<()>(
|
||||
r#"
|
||||
local tbl = setmetatable({
|
||||
userdata = userdata
|
||||
|
@ -146,7 +147,8 @@ fn test_gc_userdata() {
|
|||
hatch:access()
|
||||
"#,
|
||||
None
|
||||
).is_err());
|
||||
).is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 types::{Callback, LuaRef};
|
||||
use value::{FromLua, FromLuaMulti, ToLua, ToLuaMulti};
|
||||
use ffi;
|
||||
use lua::Lua;
|
||||
use types::{Callback, LuaRef};
|
||||
use util::{assert_stack, get_userdata, StackGuard};
|
||||
use value::{FromLua, FromLuaMulti, ToLua, ToLuaMulti};
|
||||
|
||||
/// 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)?)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue