Skip to content

Commit 23b7705

Browse files
author
Your Name
committed
add more tests for cont
1 parent 2cd34db commit 23b7705

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ pub use crate::value::{Nil, Value};
126126
#[cfg(not(feature = "luau"))]
127127
pub use crate::hook::HookTriggers;
128128

129+
#[cfg(feature = "luau")]
130+
pub use crate::thread::LuauContinuationStatus;
131+
129132
#[cfg(any(feature = "luau", doc))]
130133
#[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
131134
pub use crate::{

src/prelude.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ pub use crate::{
2828
NavigateError as LuaNavigateError, Require as LuaRequire, Vector as LuaVector,
2929
};
3030

31+
#[cfg(feature = "luau")]
32+
pub use crate::LuauContinuationStatus;
33+
3134
#[cfg(feature = "async")]
3235
#[doc(no_inline)]
3336
pub use crate::{AsyncThread as LuaAsyncThread, LuaNativeAsyncFn};

tests/luau/cont.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,11 @@ fn test_luau_continuation() {
187187
}
188188
Ok(())
189189
},
190-
|lua, _status, args: mlua::MultiValue| {
190+
|lua, status, args: mlua::MultiValue| {
191191
println!("Reached cont recursive: {:?}", args);
192192

193193
if args.len() == 5 {
194+
assert_eq!(status, mlua::LuauContinuationStatus::Ok);
194195
return 6_i32.into_lua_multi(lua);
195196
}
196197

@@ -237,4 +238,45 @@ fn test_luau_continuation() {
237238
let v = th.resume::<i32>(v).expect("Failed to load continuation");
238239

239240
assert_eq!(v, 7);
241+
242+
// test panics
243+
let cont_func = lua
244+
.create_function_with_luau_continuation(
245+
|lua, a: u64| {
246+
match lua.set_yield_args(a) {
247+
Ok(()) => println!("set_yield_args called"),
248+
Err(e) => println!("{:?}", e),
249+
};
250+
Ok(())
251+
},
252+
|_lua, _status, _a: u64| {
253+
panic!("Reached continuation which should panic!");
254+
#[allow(unreachable_code)]
255+
Ok(())
256+
},
257+
)
258+
.expect("Failed to create cont_func");
259+
260+
let luau_func = lua
261+
.load(
262+
"
263+
local cont_func = ...
264+
local ok, res = pcall(cont_func, 1)
265+
assert(not ok)
266+
return tostring(res)
267+
",
268+
)
269+
.into_function()
270+
.expect("Failed to create function");
271+
272+
let th = lua
273+
.create_thread(luau_func)
274+
.expect("Failed to create luau thread");
275+
276+
let v = th
277+
.resume::<mlua::MultiValue>(cont_func)
278+
.expect("Failed to resume");
279+
280+
let v = th.resume::<String>(v).expect("Failed to load continuation");
281+
assert!(v.contains("Reached continuation which should panic!"));
240282
}

0 commit comments

Comments
 (0)