Fix unsafe library error, add --unsafe repl option (#243)

This commit is contained in:
qwreey 2024-11-09 10:27:48 +00:00
parent 809fd566a1
commit 230632b1ca
No known key found for this signature in database
GPG key ID: D28DB79297A214BD
2 changed files with 11 additions and 3 deletions

View file

@ -18,5 +18,9 @@ pub fn set_unsafe_library_enabled(lua: &Lua, enabled: bool) {
*/ */
#[must_use] #[must_use]
pub fn get_unsafe_library_enabled(lua: &Lua) -> bool { 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
}
} }

View file

@ -17,7 +17,11 @@ enum PromptState {
/// Launch an interactive REPL (default) /// Launch an interactive REPL (default)
#[derive(Debug, Clone, Default, Parser)] #[derive(Debug, Clone, Default, Parser)]
pub struct ReplCommand {} pub struct ReplCommand {
/// Allow unsafe libraries
#[clap(long, action)]
r#unsafe: bool,
}
impl ReplCommand { impl ReplCommand {
pub async fn run(self) -> Result<ExitCode> { pub async fn run(self) -> Result<ExitCode> {
@ -38,7 +42,7 @@ impl ReplCommand {
let mut prompt_state = PromptState::Regular; let mut prompt_state = PromptState::Regular;
let mut source_code = String::new(); 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 { loop {
let prompt = match prompt_state { let prompt = match prompt_state {