mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
Resolve remaining issues when features are disabled
This commit is contained in:
parent
3b3bd54c16
commit
1941fedc9f
7 changed files with 40 additions and 28 deletions
|
@ -71,7 +71,7 @@ impl LuneStandardLibrary {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[allow(unreachable_patterns)]
|
#[allow(unreachable_patterns)]
|
||||||
pub fn module<'lua>(&self, lua: &'lua Lua) -> LuaResult<LuaMultiValue<'lua>> {
|
pub fn module<'lua>(&self, lua: &'lua Lua) -> LuaResult<LuaMultiValue<'lua>> {
|
||||||
let res = match self {
|
let res: LuaResult<LuaTable> = match self {
|
||||||
#[cfg(feature = "datetime")] Self::DateTime => lune_std_datetime::module(lua),
|
#[cfg(feature = "datetime")] Self::DateTime => lune_std_datetime::module(lua),
|
||||||
#[cfg(feature = "fs")] Self::Fs => lune_std_fs::module(lua),
|
#[cfg(feature = "fs")] Self::Fs => lune_std_fs::module(lua),
|
||||||
#[cfg(feature = "luau")] Self::Luau => lune_std_luau::module(lua),
|
#[cfg(feature = "luau")] Self::Luau => lune_std_luau::module(lua),
|
||||||
|
|
|
@ -45,7 +45,6 @@ std = [
|
||||||
]
|
]
|
||||||
|
|
||||||
cli = [
|
cli = [
|
||||||
"dep:anyhow",
|
|
||||||
"dep:env_logger",
|
"dep:env_logger",
|
||||||
"dep:clap",
|
"dep:clap",
|
||||||
"dep:include_dir",
|
"dep:include_dir",
|
||||||
|
@ -60,6 +59,7 @@ workspace = true
|
||||||
mlua = { version = "0.9.7", features = ["luau"] }
|
mlua = { version = "0.9.7", features = ["luau"] }
|
||||||
mlua-luau-scheduler = "0.0.1"
|
mlua-luau-scheduler = "0.0.1"
|
||||||
|
|
||||||
|
anyhow = "1.0"
|
||||||
console = "0.15"
|
console = "0.15"
|
||||||
dialoguer = "0.11"
|
dialoguer = "0.11"
|
||||||
directories = "5.0"
|
directories = "5.0"
|
||||||
|
@ -82,7 +82,6 @@ lune-utils = { version = "0.1.0", path = "../lune-utils" }
|
||||||
|
|
||||||
### CLI
|
### CLI
|
||||||
|
|
||||||
anyhow = { optional = true, version = "1.0" }
|
|
||||||
env_logger = { optional = true, version = "0.11" }
|
env_logger = { optional = true, version = "0.11" }
|
||||||
clap = { optional = true, version = "4.1", features = ["derive"] }
|
clap = { optional = true, version = "4.1", features = ["derive"] }
|
||||||
include_dir = { optional = true, version = "0.7", features = ["glob"] }
|
include_dir = { optional = true, version = "0.7", features = ["glob"] }
|
||||||
|
|
|
@ -3,14 +3,14 @@ use std::{env::consts::ARCH, fmt, path::PathBuf, str::FromStr};
|
||||||
use directories::BaseDirs;
|
use directories::BaseDirs;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
const HOME_DIR: Lazy<PathBuf> = Lazy::new(|| {
|
static HOME_DIR: Lazy<PathBuf> = Lazy::new(|| {
|
||||||
BaseDirs::new()
|
BaseDirs::new()
|
||||||
.expect("could not find home directory")
|
.expect("could not find home directory")
|
||||||
.home_dir()
|
.home_dir()
|
||||||
.to_path_buf()
|
.to_path_buf()
|
||||||
});
|
});
|
||||||
|
|
||||||
pub const CACHE_DIR: Lazy<PathBuf> = Lazy::new(|| HOME_DIR.join(".lune").join("target"));
|
pub static CACHE_DIR: Lazy<PathBuf> = Lazy::new(|| HOME_DIR.join(".lune").join("target"));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A target operating system supported by Lune
|
A target operating system supported by Lune
|
||||||
|
|
|
@ -1,21 +1,11 @@
|
||||||
#![deny(clippy::all)]
|
#![allow(clippy::cargo_common_metadata)]
|
||||||
#![warn(clippy::cargo, clippy::pedantic)]
|
|
||||||
#![allow(
|
|
||||||
clippy::cargo_common_metadata,
|
|
||||||
clippy::match_bool,
|
|
||||||
clippy::module_name_repetitions,
|
|
||||||
clippy::multiple_crate_versions,
|
|
||||||
clippy::needless_pass_by_value,
|
|
||||||
clippy::declare_interior_mutable_const,
|
|
||||||
clippy::borrow_interior_mutable_const
|
|
||||||
)]
|
|
||||||
|
|
||||||
use std::process::ExitCode;
|
use std::process::ExitCode;
|
||||||
|
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
pub(crate) mod cli;
|
pub(crate) mod cli;
|
||||||
pub(crate) mod standalone;
|
|
||||||
|
|
||||||
use cli::Cli;
|
pub(crate) mod standalone;
|
||||||
|
|
||||||
use lune_utils::fmt::Label;
|
use lune_utils::fmt::Label;
|
||||||
|
|
||||||
|
@ -33,11 +23,20 @@ async fn main() -> ExitCode {
|
||||||
return standalone::run(bin).await.unwrap();
|
return standalone::run(bin).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
match Cli::new().run().await {
|
#[cfg(feature = "cli")]
|
||||||
Ok(code) => code,
|
{
|
||||||
Err(err) => {
|
match cli::Cli::new().run().await {
|
||||||
eprintln!("{}\n{err:?}", Label::Error);
|
Ok(code) => code,
|
||||||
ExitCode::FAILURE
|
Err(err) => {
|
||||||
|
eprintln!("{}\n{err:?}", Label::Error);
|
||||||
|
ExitCode::FAILURE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "cli"))]
|
||||||
|
{
|
||||||
|
eprintln!("{}\nCLI feature is disabled", Label::Error);
|
||||||
|
ExitCode::FAILURE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,6 @@ use std::{
|
||||||
use mlua::Lua;
|
use mlua::Lua;
|
||||||
use mlua_luau_scheduler::Scheduler;
|
use mlua_luau_scheduler::Scheduler;
|
||||||
|
|
||||||
use lune_std::inject_globals;
|
|
||||||
|
|
||||||
use super::{RuntimeError, RuntimeResult};
|
use super::{RuntimeError, RuntimeResult};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -25,6 +23,8 @@ pub struct Runtime {
|
||||||
impl Runtime {
|
impl Runtime {
|
||||||
/**
|
/**
|
||||||
Creates a new Lune runtime, with a new Luau VM.
|
Creates a new Lune runtime, with a new Luau VM.
|
||||||
|
|
||||||
|
Injects standard globals and libraries if any of the `std` features are enabled.
|
||||||
*/
|
*/
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[allow(clippy::new_without_default)]
|
#[allow(clippy::new_without_default)]
|
||||||
|
@ -34,7 +34,21 @@ impl Runtime {
|
||||||
lua.set_app_data(Rc::downgrade(&lua));
|
lua.set_app_data(Rc::downgrade(&lua));
|
||||||
lua.set_app_data(Vec::<String>::new());
|
lua.set_app_data(Vec::<String>::new());
|
||||||
|
|
||||||
inject_globals(&lua).expect("Failed to inject globals");
|
#[cfg(any(
|
||||||
|
feature = "std-datetime",
|
||||||
|
feature = "std-fs",
|
||||||
|
feature = "std-luau",
|
||||||
|
feature = "std-net",
|
||||||
|
feature = "std-process",
|
||||||
|
feature = "std-regex",
|
||||||
|
feature = "std-roblox",
|
||||||
|
feature = "std-serde",
|
||||||
|
feature = "std-stdio",
|
||||||
|
feature = "std-task",
|
||||||
|
))]
|
||||||
|
{
|
||||||
|
lune_std::inject_globals(&lua).expect("Failed to inject globals");
|
||||||
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
lua,
|
lua,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use mlua::Compiler as LuaCompiler;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
pub const CURRENT_EXE: Lazy<PathBuf> =
|
pub static CURRENT_EXE: Lazy<PathBuf> =
|
||||||
Lazy::new(|| env::current_exe().expect("failed to get current exe"));
|
Lazy::new(|| env::current_exe().expect("failed to get current exe"));
|
||||||
const MAGIC: &[u8; 8] = b"cr3sc3nt";
|
const MAGIC: &[u8; 8] = b"cr3sc3nt";
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ macro_rules! create_tests {
|
||||||
feature = "std-roblox",
|
feature = "std-roblox",
|
||||||
feature = "std-serde",
|
feature = "std-serde",
|
||||||
feature = "std-stdio",
|
feature = "std-stdio",
|
||||||
feature = "std-task"
|
feature = "std-task",
|
||||||
))]
|
))]
|
||||||
create_tests! {
|
create_tests! {
|
||||||
require_aliases: "require/tests/aliases",
|
require_aliases: "require/tests/aliases",
|
||||||
|
|
Loading…
Add table
Reference in a new issue