From 230632b1ca7c6e5bdf101757f2792334e8a89ad6 Mon Sep 17 00:00:00 2001 From: qwreey Date: Sat, 9 Nov 2024 10:27:48 +0000 Subject: [PATCH] Fix unsafe library error, add --unsafe repl option (#243) --- crates/lune-std/src/unsafe_library.rs | 6 +++++- crates/lune/src/cli/repl.rs | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/lune-std/src/unsafe_library.rs b/crates/lune-std/src/unsafe_library.rs index 3c0cbf4..3166050 100644 --- a/crates/lune-std/src/unsafe_library.rs +++ b/crates/lune-std/src/unsafe_library.rs @@ -18,5 +18,9 @@ pub fn set_unsafe_library_enabled(lua: &Lua, enabled: bool) { */ #[must_use] pub fn get_unsafe_library_enabled(lua: &Lua) -> bool { - lua.app_data_ref::().unwrap().0 + if let Some(app_data) = lua.app_data_ref::() { + app_data.0 + } else { + false + } } diff --git a/crates/lune/src/cli/repl.rs b/crates/lune/src/cli/repl.rs index 78a6bd7..faeff73 100644 --- a/crates/lune/src/cli/repl.rs +++ b/crates/lune/src/cli/repl.rs @@ -17,7 +17,11 @@ enum PromptState { /// Launch an interactive REPL (default) #[derive(Debug, Clone, Default, Parser)] -pub struct ReplCommand {} +pub struct ReplCommand { + /// Allow unsafe libraries + #[clap(long, action)] + r#unsafe: bool, +} impl ReplCommand { pub async fn run(self) -> Result { @@ -38,7 +42,7 @@ impl ReplCommand { let mut prompt_state = PromptState::Regular; let mut source_code = String::new(); - let mut lune_instance = Runtime::new(); + let mut lune_instance = Runtime::new().set_unsafe_library_enabled(self.r#unsafe); loop { let prompt = match prompt_state {