From 2e87556a1b6182f42bf3cb2463d91dcd3e4ebb4a Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 22 Jun 2017 00:27:26 +0200 Subject: [PATCH] Add example to `LuaThread::resume` Adapted from #8 --- src/lua.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lua.rs b/src/lua.rs index 3feb350..de04474 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -569,6 +569,34 @@ impl<'lua> LuaThread<'lua> { /// /// If the thread calls `coroutine.yield`, returns the values passed to `yield`. If the thread /// `return`s values from its main function, returns those. + /// + /// # Example + /// + /// ``` + /// # extern crate rlua; + /// # use rlua::*; + /// + /// # fn main() { + /// let lua = Lua::new(); + /// let thread: LuaThread = lua.eval(r#" + /// coroutine.create(function(arg) + /// assert(arg == 42) + /// local yieldarg = coroutine.yield(123) + /// assert(yieldarg == 43) + /// return 987 + /// end) + /// "#).unwrap(); + /// + /// assert_eq!(thread.resume::<_, u32>(42).unwrap(), 123); + /// assert_eq!(thread.resume::<_, u32>(43).unwrap(), 987); + /// + /// // The coroutine has now returned, so `resume` will fail + /// match thread.resume::<_, u32>(()) { + /// Err(LuaError(LuaErrorKind::CoroutineInactive, _)) => {}, + /// unexpected => panic!("unexpected result {:?}", unexpected), + /// } + /// # } + /// ``` pub fn resume(&self, args: A) -> LuaResult where A: ToLuaMulti<'lua>,