From f75385305c9b7f9230f9f5b21ce93fb6bf295d38 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 22 Jun 2017 00:38:08 +0200 Subject: [PATCH] Add an example to `LuaFunction::bind` --- src/lua.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/lua.rs b/src/lua.rs index de04474..4a7bec3 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -494,6 +494,26 @@ impl<'lua> LuaFunction<'lua> { /// return function() f(...) end /// end /// ``` + /// + /// # Example + /// + /// ``` + /// # extern crate rlua; + /// # use rlua::*; + /// + /// # fn main() { + /// let lua = Lua::new(); + /// let globals = lua.globals().unwrap(); + /// + /// // Bind the argument `123` to Lua's `tostring` function + /// let tostring: LuaFunction = globals.get("tostring").unwrap(); + /// let tostring_123: LuaFunction = tostring.bind(123i32).unwrap(); + /// + /// // Now we can call `tostring_123` without arguments to get the result of `tostring(123)` + /// let result: String = tostring_123.call(()).unwrap(); + /// assert_eq!(result, "123"); + /// # } + /// ``` pub fn bind>(&self, args: A) -> LuaResult> { unsafe extern "C" fn bind_call_impl(state: *mut ffi::lua_State) -> c_int { let nargs = ffi::lua_gettop(state);