From d9098900d1ef68c3bc5883e0e6e3de6a83b9934b Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 16 Jul 2017 22:53:32 +0200 Subject: Give `Lua::eval` a source name param and simplify --- examples/examples.rs | 14 ++++++++------ examples/repl.rs | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'examples') diff --git a/examples/examples.rs b/examples/examples.rs index 1da1330..214ac63 100644 --- a/examples/examples.rs +++ b/examples/examples.rs @@ -37,9 +37,9 @@ fn examples() -> LuaResult<()> { )?; assert_eq!(globals.get::<_, String>("global")?, "foobar"); - assert_eq!(lua.eval::("1 + 1")?, 2); - assert_eq!(lua.eval::("false == false")?, true); - assert_eq!(lua.eval::("return 1 + 2")?, 3); + assert_eq!(lua.eval::("1 + 1", None)?, 2); + assert_eq!(lua.eval::("false == false", None)?, true); + assert_eq!(lua.eval::("return 1 + 2", None)?, 3); // You can create and manage lua tables @@ -70,7 +70,7 @@ fn examples() -> LuaResult<()> { for k, v in pairs(map_table) do print(k, v) end - "#, + "#, None )?; // You can load lua functions @@ -118,16 +118,18 @@ fn examples() -> LuaResult<()> { assert_eq!( lua.eval::( r#"check_equal({"a", "b", "c"}, {"a", "b", "c"})"#, + None )?, true ); assert_eq!( lua.eval::( r#"check_equal({"a", "b", "c"}, {"d", "e", "f"})"#, + None )?, false ); - assert_eq!(lua.eval::(r#"join("a", "b", "c")"#)?, "abc"); + assert_eq!(lua.eval::(r#"join("a", "b", "c")"#, None)?, "abc"); // You can create userdata with methods and metamethods defined on them. // Here's a worked example that shows many of the features of this API @@ -156,7 +158,7 @@ fn examples() -> LuaResult<()> { }); globals.set("vec2", vec2_constructor)?; - assert!(lua.eval::("(vec2(1, 2) + vec2(2, 2)):magnitude()")? - 5.0 < f32::EPSILON); + assert!(lua.eval::("(vec2(1, 2) + vec2(2, 2)):magnitude()", None)? - 5.0 < f32::EPSILON); Ok(()) } diff --git a/examples/repl.rs b/examples/repl.rs index 1f8b99d..cae2465 100644 --- a/examples/repl.rs +++ b/examples/repl.rs @@ -20,7 +20,7 @@ fn main() { loop { stdin.read_line(&mut line).unwrap(); - match lua.eval::(&line) { + match lua.eval::(&line, None) { Ok(values) => { println!( "{}", -- cgit v1.2.3