mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Replace lazy_static with once_cell
This commit is contained in:
parent
191bbf15bb
commit
e9bea839b3
10 changed files with 54 additions and 58 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -1011,9 +1011,9 @@ dependencies = [
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"hyper",
|
"hyper",
|
||||||
"hyper-tungstenite",
|
"hyper-tungstenite",
|
||||||
"lazy_static",
|
|
||||||
"lune-roblox",
|
"lune-roblox",
|
||||||
"mlua",
|
"mlua",
|
||||||
|
"once_cell",
|
||||||
"os_str_bytes",
|
"os_str_bytes",
|
||||||
"pin-project",
|
"pin-project",
|
||||||
"rbx_cookie",
|
"rbx_cookie",
|
||||||
|
@ -1037,8 +1037,8 @@ dependencies = [
|
||||||
"full_moon",
|
"full_moon",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"include_dir",
|
"include_dir",
|
||||||
"lazy_static",
|
|
||||||
"lune",
|
"lune",
|
||||||
|
"once_cell",
|
||||||
"regex",
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -1052,8 +1052,8 @@ version = "0.6.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"glam",
|
"glam",
|
||||||
"lazy_static",
|
|
||||||
"mlua",
|
"mlua",
|
||||||
|
"once_cell",
|
||||||
"rand",
|
"rand",
|
||||||
"rbx_binary",
|
"rbx_binary",
|
||||||
"rbx_dom_weak",
|
"rbx_dom_weak",
|
||||||
|
|
|
@ -19,7 +19,7 @@ categories = ["command-line-interface"]
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
console = "0.15"
|
console = "0.15"
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
lazy_static = "1.4"
|
once_cell = "1.17"
|
||||||
|
|
||||||
mlua = { version = "0.8", features = ["luau", "serialize"] }
|
mlua = { version = "0.8", features = ["luau", "serialize"] }
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ lune = { path = "../lib" }
|
||||||
|
|
||||||
console.workspace = true
|
console.workspace = true
|
||||||
futures-util.workspace = true
|
futures-util.workspace = true
|
||||||
lazy_static.workspace = true
|
once_cell.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
serde_yaml.workspace = true
|
serde_yaml.workspace = true
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use serde_json::{Map as JsonMap, Value as JsonValue};
|
use serde_json::{Map as JsonMap, Value as JsonValue};
|
||||||
|
|
||||||
use super::definitions::{DefinitionsItem, DefinitionsItemTag, DefinitionsTree};
|
use super::definitions::{DefinitionsItem, DefinitionsItemTag, DefinitionsTree};
|
||||||
|
|
||||||
lazy_static! {
|
static KEY_DOCUMENTATION: &str = "documentation";
|
||||||
static ref KEY_DOCUMENTATION: String = "documentation".to_string();
|
static KEY_KEYS: &str = "keys";
|
||||||
static ref KEY_KEYS: String = "keys".to_string();
|
static KEY_NAME: &str = "name";
|
||||||
static ref KEY_NAME: String = "name".to_string();
|
static KEY_CODE_SAMPLE: &str = "code_sample";
|
||||||
static ref KEY_CODE_SAMPLE: String = "code_sample".to_string();
|
static KEY_LEARN_MORE_LINK: &str = "learn_more_link";
|
||||||
static ref KEY_LEARN_MORE_LINK: String = "learn_more_link".to_string();
|
static VALUE_EMPTY: &str = "";
|
||||||
static ref VALUE_EMPTY: String = String::new();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn generate_from_type_definitions(contents: &str, namespace: &str) -> Result<String> {
|
pub fn generate_from_type_definitions(contents: &str, namespace: &str) -> Result<String> {
|
||||||
let tree = DefinitionsTree::from_type_definitions(contents)?;
|
let tree = DefinitionsTree::from_type_definitions(contents)?;
|
||||||
|
@ -91,24 +88,27 @@ fn parse_and_insert(
|
||||||
.context("Missing description value for doc item")?
|
.context("Missing description value for doc item")?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
item_map.insert(KEY_DOCUMENTATION.clone(), JsonValue::String(description));
|
item_map.insert(
|
||||||
|
KEY_DOCUMENTATION.to_string(),
|
||||||
|
JsonValue::String(description),
|
||||||
|
);
|
||||||
if let Some(code_sample) = code_sample {
|
if let Some(code_sample) = code_sample {
|
||||||
item_map.insert(KEY_CODE_SAMPLE.clone(), JsonValue::String(code_sample));
|
item_map.insert(KEY_CODE_SAMPLE.to_string(), JsonValue::String(code_sample));
|
||||||
} else {
|
} else {
|
||||||
item_map.insert(
|
item_map.insert(
|
||||||
KEY_CODE_SAMPLE.clone(),
|
KEY_CODE_SAMPLE.to_string(),
|
||||||
JsonValue::String(VALUE_EMPTY.clone()),
|
JsonValue::String(VALUE_EMPTY.to_string()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Some(learn_more_link) = learn_more_link {
|
if let Some(learn_more_link) = learn_more_link {
|
||||||
item_map.insert(
|
item_map.insert(
|
||||||
KEY_LEARN_MORE_LINK.clone(),
|
KEY_LEARN_MORE_LINK.to_string(),
|
||||||
JsonValue::String(learn_more_link),
|
JsonValue::String(learn_more_link),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
item_map.insert(
|
item_map.insert(
|
||||||
KEY_LEARN_MORE_LINK.clone(),
|
KEY_LEARN_MORE_LINK.to_string(),
|
||||||
JsonValue::String(VALUE_EMPTY.clone()),
|
JsonValue::String(VALUE_EMPTY.to_string()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ fn parse_and_insert(
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
if keys.is_empty() {
|
if keys.is_empty() {
|
||||||
item_map.insert("keys".to_string(), JsonValue::Object(JsonMap::new()));
|
item_map.insert(KEY_KEYS.to_string(), JsonValue::Object(JsonMap::new()));
|
||||||
} else {
|
} else {
|
||||||
let mut keys_map = JsonMap::new();
|
let mut keys_map = JsonMap::new();
|
||||||
for key in keys.drain(..) {
|
for key in keys.drain(..) {
|
||||||
|
@ -143,7 +143,7 @@ fn parse_and_insert(
|
||||||
JsonValue::String(format!("@{namespace}/{item_name_full}.{key}")),
|
JsonValue::String(format!("@{namespace}/{item_name_full}.{key}")),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
item_map.insert("keys".to_string(), JsonValue::Object(keys_map));
|
item_map.insert(KEY_KEYS.to_string(), JsonValue::Object(keys_map));
|
||||||
}
|
}
|
||||||
} else if item.is_function() {
|
} else if item.is_function() {
|
||||||
// Add links to params
|
// Add links to params
|
||||||
|
@ -154,9 +154,9 @@ fn parse_and_insert(
|
||||||
for (index, param) in params.iter().enumerate() {
|
for (index, param) in params.iter().enumerate() {
|
||||||
let mut param_map = JsonMap::new();
|
let mut param_map = JsonMap::new();
|
||||||
if let DefinitionsItemTag::Param((name, _)) = param {
|
if let DefinitionsItemTag::Param((name, _)) = param {
|
||||||
param_map.insert(KEY_NAME.clone(), JsonValue::String(name.to_string()));
|
param_map.insert(KEY_NAME.to_string(), JsonValue::String(name.to_string()));
|
||||||
param_map.insert(
|
param_map.insert(
|
||||||
KEY_DOCUMENTATION.clone(),
|
KEY_DOCUMENTATION.to_string(),
|
||||||
JsonValue::String(format!("@{namespace}/{item_name_full}/param/{index}")),
|
JsonValue::String(format!("@{namespace}/{item_name_full}/param/{index}")),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ fn parse_and_insert(
|
||||||
let mut param_map = JsonMap::new();
|
let mut param_map = JsonMap::new();
|
||||||
if let DefinitionsItemTag::Param((_, doc)) = param {
|
if let DefinitionsItemTag::Param((_, doc)) = param {
|
||||||
param_map.insert(
|
param_map.insert(
|
||||||
KEY_DOCUMENTATION.clone(),
|
KEY_DOCUMENTATION.to_string(),
|
||||||
JsonValue::String(format!("{doc}\n\n---\n")),
|
JsonValue::String(format!("{doc}\n\n---\n")),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ fn parse_and_insert(
|
||||||
let mut return_map = JsonMap::new();
|
let mut return_map = JsonMap::new();
|
||||||
if let DefinitionsItemTag::Return(doc) = ret {
|
if let DefinitionsItemTag::Return(doc) = ret {
|
||||||
return_map.insert(
|
return_map.insert(
|
||||||
KEY_DOCUMENTATION.clone(),
|
KEY_DOCUMENTATION.to_string(),
|
||||||
JsonValue::String(doc.to_string()),
|
JsonValue::String(doc.to_string()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,12 @@ use std::{
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use console::style;
|
use console::style;
|
||||||
use lazy_static::lazy_static;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
const LUNE_COMMENT_PREFIX: &str = "-->";
|
const LUNE_COMMENT_PREFIX: &str = "-->";
|
||||||
|
|
||||||
lazy_static! {
|
static ERR_MESSAGE_HELP_NOTE: Lazy<String> = Lazy::new(|| {
|
||||||
static ref ERR_MESSAGE_HELP_NOTE: String = format!(
|
format!(
|
||||||
"To run this file, either:\n{}\n{}",
|
"To run this file, either:\n{}\n{}",
|
||||||
format_args!(
|
format_args!(
|
||||||
"{} rename it to use a {} or {} extension",
|
"{} rename it to use a {} or {} extension",
|
||||||
|
@ -22,8 +22,8 @@ lazy_static! {
|
||||||
"{} pass it as an absolute path instead of relative",
|
"{} pass it as an absolute path instead of relative",
|
||||||
style("-").dim()
|
style("-").dim()
|
||||||
),
|
),
|
||||||
);
|
)
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Discovers a script file path based on a given script name.
|
Discovers a script file path based on a given script name.
|
||||||
|
|
|
@ -2,15 +2,13 @@ use std::{cmp::Ordering, fmt::Write as _};
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use console::Style;
|
use console::Style;
|
||||||
use lazy_static::lazy_static;
|
use once_cell::sync::Lazy;
|
||||||
use tokio::{fs, io};
|
use tokio::{fs, io};
|
||||||
|
|
||||||
use super::files::parse_lune_description_from_file;
|
use super::files::parse_lune_description_from_file;
|
||||||
|
|
||||||
lazy_static! {
|
pub static COLOR_BLUE: Lazy<Style> = Lazy::new(|| Style::new().blue());
|
||||||
pub static ref COLOR_BLUE: Style = Style::new().blue();
|
pub static STYLE_DIM: Lazy<Style> = Lazy::new(|| Style::new().dim());
|
||||||
pub static ref STYLE_DIM: Style = Style::new().dim();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn find_lune_scripts() -> Result<Vec<(String, String)>> {
|
pub async fn find_lune_scripts() -> Result<Vec<(String, String)>> {
|
||||||
let mut lune_dir = fs::read_dir("lune").await;
|
let mut lune_dir = fs::read_dir("lune").await;
|
||||||
|
|
|
@ -16,7 +16,7 @@ path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
mlua.workspace = true
|
mlua.workspace = true
|
||||||
lazy_static.workspace = true
|
once_cell.workspace = true
|
||||||
|
|
||||||
glam = "0.23"
|
glam = "0.23"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use rbx_dom_weak::{
|
use rbx_dom_weak::{
|
||||||
types::{Ref as DomRef, Variant as DomValue, VariantType as DomType},
|
types::{Ref as DomRef, Variant as DomValue, VariantType as DomType},
|
||||||
Instance as DomInstance, InstanceBuilder as DomInstanceBuilder, WeakDom,
|
Instance as DomInstance, InstanceBuilder as DomInstanceBuilder, WeakDom,
|
||||||
|
@ -22,10 +23,8 @@ use crate::{
|
||||||
|
|
||||||
pub(crate) mod data_model;
|
pub(crate) mod data_model;
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
static INTERNAL_DOM: Lazy<RwLock<WeakDom>> =
|
||||||
static ref INTERNAL_DOM: RwLock<WeakDom> =
|
Lazy::new(|| RwLock::new(WeakDom::new(DomInstanceBuilder::new("ROOT"))));
|
||||||
RwLock::new(WeakDom::new(DomInstanceBuilder::new("ROOT")));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
|
|
|
@ -24,8 +24,8 @@ rbx_cookie = { version = "0.1.2", optional = true }
|
||||||
|
|
||||||
console.workspace = true
|
console.workspace = true
|
||||||
futures-util.workspace = true
|
futures-util.workspace = true
|
||||||
lazy_static.workspace = true
|
|
||||||
mlua.workspace = true
|
mlua.workspace = true
|
||||||
|
once_cell.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
serde_yaml.workspace = true
|
serde_yaml.workspace = true
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
use console::{colors_enabled, set_colors_enabled, style, Style};
|
use console::{colors_enabled, set_colors_enabled, style, Style};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use crate::lua::task::TaskReference;
|
use crate::lua::task::TaskReference;
|
||||||
|
|
||||||
|
@ -12,20 +12,19 @@ const INDENT: &str = " ";
|
||||||
|
|
||||||
pub const STYLE_RESET_STR: &str = "\x1b[0m";
|
pub const STYLE_RESET_STR: &str = "\x1b[0m";
|
||||||
|
|
||||||
lazy_static! {
|
// Colors
|
||||||
// Colors
|
pub static COLOR_BLACK: Lazy<Style> = Lazy::new(|| Style::new().black());
|
||||||
pub static ref COLOR_BLACK: Style = Style::new().black();
|
pub static COLOR_RED: Lazy<Style> = Lazy::new(|| Style::new().red());
|
||||||
pub static ref COLOR_RED: Style = Style::new().red();
|
pub static COLOR_GREEN: Lazy<Style> = Lazy::new(|| Style::new().green());
|
||||||
pub static ref COLOR_GREEN: Style = Style::new().green();
|
pub static COLOR_YELLOW: Lazy<Style> = Lazy::new(|| Style::new().yellow());
|
||||||
pub static ref COLOR_YELLOW: Style = Style::new().yellow();
|
pub static COLOR_BLUE: Lazy<Style> = Lazy::new(|| Style::new().blue());
|
||||||
pub static ref COLOR_BLUE: Style = Style::new().blue();
|
pub static COLOR_PURPLE: Lazy<Style> = Lazy::new(|| Style::new().magenta());
|
||||||
pub static ref COLOR_PURPLE: Style = Style::new().magenta();
|
pub static COLOR_CYAN: Lazy<Style> = Lazy::new(|| Style::new().cyan());
|
||||||
pub static ref COLOR_CYAN: Style = Style::new().cyan();
|
pub static COLOR_WHITE: Lazy<Style> = Lazy::new(|| Style::new().white());
|
||||||
pub static ref COLOR_WHITE: Style = Style::new().white();
|
|
||||||
// Styles
|
// Styles
|
||||||
pub static ref STYLE_BOLD: Style = Style::new().bold();
|
pub static STYLE_BOLD: Lazy<Style> = Lazy::new(|| Style::new().bold());
|
||||||
pub static ref STYLE_DIM: Style = Style::new().dim();
|
pub static STYLE_DIM: Lazy<Style> = Lazy::new(|| Style::new().dim());
|
||||||
}
|
|
||||||
|
|
||||||
fn can_be_plain_lua_table_key(s: &LuaString) -> bool {
|
fn can_be_plain_lua_table_key(s: &LuaString) -> bool {
|
||||||
let str = s.to_string_lossy().to_string();
|
let str = s.to_string_lossy().to_string();
|
||||||
|
|
Loading…
Reference in a new issue