auto formatting
This commit is contained in:
parent
bfb6111e0a
commit
ad23fe83e0
|
@ -72,13 +72,12 @@ impl Lua {
|
||||||
check_stack(self.state, 1);
|
check_stack(self.state, 1);
|
||||||
|
|
||||||
match if let Some(name) = name {
|
match if let Some(name) = name {
|
||||||
let name = CString::new(name.to_owned()).map_err(|e| {
|
let name =
|
||||||
Error::ToLuaConversionError {
|
CString::new(name.to_owned()).map_err(|e| Error::ToLuaConversionError {
|
||||||
from: "&str",
|
from: "&str",
|
||||||
to: "string",
|
to: "string",
|
||||||
message: Some(e.to_string()),
|
message: Some(e.to_string()),
|
||||||
}
|
})?;
|
||||||
})?;
|
|
||||||
ffi::luaL_loadbuffer(
|
ffi::luaL_loadbuffer(
|
||||||
self.state,
|
self.state,
|
||||||
source.as_ptr() as *const c_char,
|
source.as_ptr() as *const c_char,
|
||||||
|
|
|
@ -35,12 +35,10 @@ impl<'lua> String<'lua> {
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn to_str(&self) -> Result<&str> {
|
pub fn to_str(&self) -> Result<&str> {
|
||||||
str::from_utf8(self.as_bytes()).map_err(|e| {
|
str::from_utf8(self.as_bytes()).map_err(|e| Error::FromLuaConversionError {
|
||||||
Error::FromLuaConversionError {
|
from: "string",
|
||||||
from: "string",
|
to: "&str",
|
||||||
to: "&str",
|
message: Some(e.to_string()),
|
||||||
message: Some(e.to_string()),
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,20 +152,19 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_thread() {
|
fn test_thread() {
|
||||||
let lua = Lua::new();
|
let lua = Lua::new();
|
||||||
let thread = lua.create_thread(
|
let thread = lua.create_thread(lua.eval::<Function>(
|
||||||
lua.eval::<Function>(
|
r#"
|
||||||
r#"
|
function (s)
|
||||||
function (s)
|
local sum = s
|
||||||
local sum = s
|
for i = 1,4 do
|
||||||
for i = 1,4 do
|
sum = sum + coroutine.yield(sum)
|
||||||
sum = sum + coroutine.yield(sum)
|
|
||||||
end
|
|
||||||
return sum
|
|
||||||
end
|
end
|
||||||
"#,
|
return sum
|
||||||
None,
|
end
|
||||||
).unwrap(),
|
"#,
|
||||||
).unwrap();
|
None,
|
||||||
|
).unwrap())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(thread.status(), ThreadStatus::Resumable);
|
assert_eq!(thread.status(), ThreadStatus::Resumable);
|
||||||
assert_eq!(thread.resume::<_, i64>(0).unwrap(), 0);
|
assert_eq!(thread.resume::<_, i64>(0).unwrap(), 0);
|
||||||
|
@ -179,18 +178,17 @@ mod tests {
|
||||||
assert_eq!(thread.resume::<_, i64>(4).unwrap(), 10);
|
assert_eq!(thread.resume::<_, i64>(4).unwrap(), 10);
|
||||||
assert_eq!(thread.status(), ThreadStatus::Unresumable);
|
assert_eq!(thread.status(), ThreadStatus::Unresumable);
|
||||||
|
|
||||||
let accumulate = lua.create_thread(
|
let accumulate = lua.create_thread(lua.eval::<Function>(
|
||||||
lua.eval::<Function>(
|
r#"
|
||||||
r#"
|
function (sum)
|
||||||
function (sum)
|
while true do
|
||||||
while true do
|
sum = sum + coroutine.yield(sum)
|
||||||
sum = sum + coroutine.yield(sum)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
"#,
|
end
|
||||||
None,
|
"#,
|
||||||
).unwrap(),
|
None,
|
||||||
).unwrap();
|
).unwrap())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
for i in 0..4 {
|
for i in 0..4 {
|
||||||
accumulate.resume::<_, ()>(i).unwrap();
|
accumulate.resume::<_, ()>(i).unwrap();
|
||||||
|
|
Loading…
Reference in New Issue