From 9cb1ba43d085c4eea234b3290b18ddfd7d302419 Mon Sep 17 00:00:00 2001 From: Erica Marigold <hi@devcomp.xyz> Date: Thu, 11 Apr 2024 18:18:10 +0530 Subject: [PATCH] fix(Runtime): remove unwraps and handle None case This commit removes the chained unwraps introduced previously with a match statement which handles the case when a lua thread may return no values. --- src/lune/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lune/mod.rs b/src/lune/mod.rs index 0f2ad02..b54c584 100644 --- a/src/lune/mod.rs +++ b/src/lune/mod.rs @@ -7,7 +7,7 @@ use std::{ }, }; -use mlua::{Lua, Value}; +use mlua::{IntoLuaMulti, Lua, Value}; use mlua_luau_scheduler::Scheduler; mod builtins; @@ -86,11 +86,11 @@ impl Runtime { let main_thread_id = sched.push_thread_back(main, ())?; sched.run().await; - let thread_res = sched - .get_thread_result(main_thread_id) - .unwrap() - .unwrap() - .into_vec(); + let thread_res = match sched.get_thread_result(main_thread_id) { + Some(res) => res, + None => Value::Nil.into_lua_multi(&self.lua), + }? + .into_vec(); Ok(( sched.get_exit_code().unwrap_or({ if got_any_error.load(Ordering::SeqCst) {