mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 04:50:36 +00:00
Rename lune struct to runtime
This commit is contained in:
parent
ef9550ced5
commit
e5e83d1ad6
9 changed files with 26 additions and 31 deletions
|
@ -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])
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<ExitCode> {
|
|||
let args = env::args().skip(1).collect::<Vec<_>>();
|
||||
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;
|
||||
|
|
|
@ -6,4 +6,4 @@ pub mod roblox;
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub use crate::lune::{Lune, LuneError};
|
||||
pub use crate::lune::{Runtime, RuntimeError};
|
||||
|
|
|
@ -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<LuaError> for LuneError {
|
||||
impl From<LuaError> for RuntimeError {
|
||||
fn from(value: LuaError) -> Self {
|
||||
Self {
|
||||
error: value,
|
||||
|
@ -66,7 +64,7 @@ impl From<LuaError> 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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String>,
|
||||
}
|
||||
|
||||
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<str>,
|
||||
script_contents: impl AsRef<[u8]>,
|
||||
) -> Result<ExitCode, LuneError> {
|
||||
) -> Result<ExitCode, RuntimeError> {
|
||||
let main = self
|
||||
.lua
|
||||
.load(script_contents.as_ref())
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue