summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2017-07-25 00:05:36 +0200
committerJonas Schievink <jonasschievink@gmail.com>2017-07-25 00:05:36 +0200
commit59ab95f6ffd4d9f2eaf6de462230a7c07430658a (patch)
tree724e6c9e12e839eb45e9be3e36c1b20c63dc3de1 /src
parent63e0587d2665fd2abc732f0c55e89868f3a8a2d4 (diff)
downloadmlua-59ab95f6ffd4d9f2eaf6de462230a7c07430658a.zip
Beef up Function::bind docs + example
Diffstat (limited to 'src')
-rw-r--r--src/lua.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/lua.rs b/src/lua.rs
index 148c3d9..0370b6b 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -498,9 +498,11 @@ impl<'lua> Function<'lua> {
}
}
- /// Returns a function that, when called with no arguments, calls `self`, passing `args` as
+ /// Returns a function that, when called, calls `self`, passing `args` as the first set of
/// arguments.
///
+ /// If any arguments are passed to the returned function, they will be passed after `args`.
+ ///
/// # Example
///
/// ```
@@ -508,15 +510,19 @@ impl<'lua> Function<'lua> {
/// # use rlua::{Lua, Function, Result};
/// # fn try_main() -> Result<()> {
/// let lua = Lua::new();
- /// let globals = lua.globals();
///
- /// // Bind the argument `123` to Lua's `tostring` function
- /// let tostring: Function = globals.get("tostring")?;
- /// let tostring_123: Function = tostring.bind(123i32)?;
+ /// let sum: Function = lua.eval(r#"
+ /// function(a, b)
+ /// return a + b
+ /// end
+ /// "#, None)?;
+ ///
+ /// let bound_a = sum.bind(1)?;
+ /// assert_eq!(bound_a.call::<_, u32>(2)?, 1 + 2);
+ ///
+ /// let bound_a_and_b = sum.bind(13)?.bind(57)?;
+ /// assert_eq!(bound_a_and_b.call::<_, u32>(())?, 13 + 57);
///
- /// // Now we can call `tostring_123` without arguments to get the result of `tostring(123)`
- /// let result: String = tostring_123.call(())?;
- /// assert_eq!(result, "123");
/// # Ok(())
/// # }
/// # fn main() {