diff options
author | kyren <kerriganw@gmail.com> | 2017-07-19 20:10:11 -0400 |
---|---|---|
committer | kyren <kerriganw@gmail.com> | 2017-07-19 20:10:11 -0400 |
commit | 160c5405e1af8127070c1486f99d8842736304d2 (patch) | |
tree | 5c369f2fc721d098ea3e2cb5ce1e8c058a405332 /src | |
parent | 4f2d894a52a06e91da1a0f690b9cc932b81bdb85 (diff) | |
download | mlua-160c5405e1af8127070c1486f99d8842736304d2.zip |
Add back explanatory comment about trying "return <expr>" before statement
Also run through rustfmt
Diffstat (limited to 'src')
-rw-r--r-- | src/lua.rs | 5 | ||||
-rw-r--r-- | src/tests.rs | 22 |
2 files changed, 20 insertions, 7 deletions
@@ -1087,8 +1087,11 @@ impl Lua { pub fn eval<'lua, R: FromLuaMulti<'lua>>( &'lua self, source: &str, - name: Option<&str> + name: Option<&str>, ) -> LuaResult<R> { + // First, try interpreting the lua as an expression by adding + // "return", then as a statement. This is the same thing the + // actual lua repl does. self.load(&format!("return {}", source), name) .or_else(|_| self.load(source, name))? .call(()) diff --git a/src/tests.rs b/src/tests.rs index 92f44f2..0dcfb67 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -323,8 +323,18 @@ fn test_metamethods() { let globals = lua.globals(); globals.set("userdata1", UserData(7)).unwrap(); globals.set("userdata2", UserData(3)).unwrap(); - assert_eq!(lua.eval::<UserData>("userdata1 + userdata2", None).unwrap().0, 10); - assert_eq!(lua.eval::<UserData>("userdata1 - userdata2", None).unwrap().0, 4); + assert_eq!( + lua.eval::<UserData>("userdata1 + userdata2", None) + .unwrap() + .0, + 10 + ); + assert_eq!( + lua.eval::<UserData>("userdata1 - userdata2", None) + .unwrap() + .0, + 4 + ); assert_eq!(lua.eval::<i64>("userdata1:get()", None).unwrap(), 7); assert_eq!(lua.eval::<i64>("userdata2.inner", None).unwrap(), 3); assert!(lua.eval::<()>("userdata2.nonexist_field", None).is_err()); @@ -610,7 +620,7 @@ fn test_thread() { return sum end "#, - None + None, ).unwrap(), ); @@ -635,7 +645,7 @@ fn test_thread() { end end "#, - None + None, ).unwrap(), ); @@ -655,7 +665,7 @@ fn test_thread() { end end) "#, - None + None, ).unwrap(); assert_eq!(thread.status(), LuaThreadStatus::Active); assert_eq!(thread.resume::<_, i64>(()).unwrap(), 42); @@ -669,7 +679,7 @@ fn test_thread() { return 987 end) "#, - None + None, ).unwrap(); assert_eq!(thread.resume::<_, u32>(42).unwrap(), 123); |