Skip to content

Commit

Permalink
Fix unsafe library error, add --unsafe repl option (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwreey committed Nov 9, 2024
1 parent 809fd56 commit 230632b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion crates/lune-std/src/unsafe_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<UnsafeLibrary>().unwrap().0
if let Some(app_data) = lua.app_data_ref::<UnsafeLibrary>() {
app_data.0
} else {
false
}
}
8 changes: 6 additions & 2 deletions crates/lune/src/cli/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExitCode> {
Expand All @@ -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 {
Expand Down

0 comments on commit 230632b

Please sign in to comment.