diff --git a/CHANGELOG.md b/CHANGELOG.md index e88c94f..1a55adc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 This unfortunately hurts ergonomics for quickly running scripts but is a necessary change to allow us to add more commands, such as the new `build` subcommand. +- The `Lune` struct has been renamed to `Runtime` in the Lune rust crate. + ### Added - Added support for compiling single Lune scripts into standalone executables! ([#140]) diff --git a/src/cli/repl.rs b/src/cli/repl.rs index 915a314..78a6bd7 100644 --- a/src/cli/repl.rs +++ b/src/cli/repl.rs @@ -5,7 +5,7 @@ use clap::Parser; use directories::UserDirs; use rustyline::{error::ReadlineError, DefaultEditor}; -use lune::Lune; +use lune::Runtime; const MESSAGE_WELCOME: &str = concat!("Lune v", env!("CARGO_PKG_VERSION")); const MESSAGE_INTERRUPT: &str = "Interrupt: ^C again to exit"; @@ -38,7 +38,7 @@ impl ReplCommand { let mut prompt_state = PromptState::Regular; let mut source_code = String::new(); - let mut lune_instance = Lune::new(); + let mut lune_instance = Runtime::new(); loop { let prompt = match prompt_state { diff --git a/src/cli/run.rs b/src/cli/run.rs index e5877a7..35e523e 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -7,7 +7,7 @@ use tokio::{ io::{stdin, AsyncReadExt as _}, }; -use lune::Lune; +use lune::Runtime; use super::utils::files::{discover_script_path_including_lune_dirs, strip_shebang}; @@ -41,7 +41,7 @@ impl RunCommand { }; // Create a new lune object with all globals & run the script - let result = Lune::new() + let result = Runtime::new() .with_args(self.script_args) .run(&script_display_name, strip_shebang(script_contents)) .await; diff --git a/src/executor.rs b/src/executor.rs index 0b6f3f0..3921537 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -1,6 +1,6 @@ use std::{env, process::ExitCode}; -use lune::Lune; +use lune::Runtime; use anyhow::{bail, Result}; use tokio::fs; @@ -68,7 +68,7 @@ pub async fn run_standalone(patched_bin: impl AsRef<[u8]>) -> Result { let args = env::args().skip(1).collect::>(); let meta = MetaChunk::from_bytes(patched_bin).expect("must be a standalone binary"); - let result = Lune::new() + let result = Runtime::new() .with_args(args) .run("STANDALONE", meta.bytecode) .await; diff --git a/src/lib.rs b/src/lib.rs index b798775..eaaa157 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,4 +6,4 @@ pub mod roblox; #[cfg(test)] mod tests; -pub use crate::lune::{Lune, LuneError}; +pub use crate::lune::{Runtime, RuntimeError}; diff --git a/src/lune/error.rs b/src/lune/error.rs index bde101a..840913d 100644 --- a/src/lune/error.rs +++ b/src/lune/error.rs @@ -11,14 +11,12 @@ use crate::lune::util::formatting::pretty_format_luau_error; An opaque error type for formatted lua errors. */ #[derive(Debug, Clone)] -pub struct LuneError { +pub struct RuntimeError { error: LuaError, disable_colors: bool, } -// TODO: Rename this struct to "RuntimeError" instead for -// the next breaking release, it's a more fitting name -impl LuneError { +impl RuntimeError { /** Enables colorization of the error message when formatted using the [`Display`] trait. @@ -57,7 +55,7 @@ impl LuneError { } } -impl From for LuneError { +impl From for RuntimeError { fn from(value: LuaError) -> Self { Self { error: value, @@ -66,7 +64,7 @@ impl From for LuneError { } } -impl From<&LuaError> for LuneError { +impl From<&LuaError> for RuntimeError { fn from(value: &LuaError) -> Self { Self { error: value.clone(), @@ -75,7 +73,7 @@ impl From<&LuaError> for LuneError { } } -impl Display for LuneError { +impl Display for RuntimeError { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { write!( f, @@ -85,10 +83,8 @@ impl Display for LuneError { } } -impl Error for LuneError { - // TODO: Comment this out when we are ready to also re-export - // `mlua` as part of our public library interface in Lune - // fn cause(&self) -> Option<&dyn Error> { - // Some(&self.error) - // } +impl Error for RuntimeError { + fn cause(&self) -> Option<&dyn Error> { + Some(&self.error) + } } diff --git a/src/lune/mod.rs b/src/lune/mod.rs index caa6f1a..6eda448 100644 --- a/src/lune/mod.rs +++ b/src/lune/mod.rs @@ -11,19 +11,16 @@ pub(crate) mod util; use self::scheduler::{LuaSchedulerExt, Scheduler}; -pub use error::LuneError; +pub use error::RuntimeError; -// TODO: Rename this struct to "Runtime" instead for the -// next breaking release, it's a more fitting name and -// will probably be more obvious when browsing files #[derive(Debug, Clone)] -pub struct Lune { +pub struct Runtime { lua: &'static Lua, scheduler: &'static Scheduler<'static>, args: Vec, } -impl Lune { +impl Runtime { /** Creates a new Lune runtime, with a new Luau VM and task scheduler. */ @@ -70,7 +67,7 @@ impl Lune { &mut self, script_name: impl AsRef, script_contents: impl AsRef<[u8]>, - ) -> Result { + ) -> Result { let main = self .lua .load(script_contents.as_ref()) diff --git a/src/lune/util/traits.rs b/src/lune/util/traits.rs index 32c514d..2c75d65 100644 --- a/src/lune/util/traits.rs +++ b/src/lune/util/traits.rs @@ -1,7 +1,7 @@ use mlua::prelude::*; use super::formatting::format_label; -use crate::LuneError; +use crate::RuntimeError; pub trait LuaEmitErrorExt { fn emit_error(&self, err: LuaError); @@ -10,6 +10,6 @@ pub trait LuaEmitErrorExt { impl LuaEmitErrorExt for Lua { fn emit_error(&self, err: LuaError) { // NOTE: LuneError will pretty-format this error - eprintln!("{}\n{}", format_label("error"), LuneError::from(err)); + eprintln!("{}\n{}", format_label("error"), RuntimeError::from(err)); } } diff --git a/src/tests.rs b/src/tests.rs index a773fda..eb364fa 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -5,7 +5,7 @@ use console::set_colors_enabled; use console::set_colors_enabled_stderr; use tokio::fs::read_to_string; -use crate::Lune; +use crate::Runtime; const ARGS: &[&str] = &["Foo", "Bar"]; @@ -20,7 +20,7 @@ macro_rules! create_tests { // The rest of the test logic can continue as normal let full_name = format!("tests/{}.luau", $value); let script = read_to_string(&full_name).await?; - let mut lune = Lune::new().with_args( + let mut lune = Runtime::new().with_args( ARGS .clone() .iter()