mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
Fix version string using lune-utils version instead of lune version, add inject_globals to lune-std
This commit is contained in:
parent
a714efdac4
commit
5a52a51aa2
3 changed files with 40 additions and 12 deletions
|
@ -3,6 +3,6 @@ use mlua::prelude::*;
|
||||||
use lune_utils::get_version_string;
|
use lune_utils::get_version_string;
|
||||||
|
|
||||||
pub fn create(lua: &Lua) -> LuaResult<LuaValue> {
|
pub fn create(lua: &Lua) -> LuaResult<LuaValue> {
|
||||||
let s = get_version_string().to_string();
|
let s = get_version_string(env!("CARGO_PKG_VERSION"));
|
||||||
lua.create_string(s)?.into_lua(lua)
|
lua.create_string(s)?.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,27 @@
|
||||||
#![allow(clippy::cargo_common_metadata)]
|
#![allow(clippy::cargo_common_metadata)]
|
||||||
|
|
||||||
|
use mlua::prelude::*;
|
||||||
|
|
||||||
mod global;
|
mod global;
|
||||||
mod globals;
|
mod globals;
|
||||||
mod library;
|
mod library;
|
||||||
|
|
||||||
pub use self::global::LuneStandardGlobal;
|
pub use self::global::LuneStandardGlobal;
|
||||||
pub use self::library::LuneStandardLibrary;
|
pub use self::library::LuneStandardLibrary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Injects all standard globals into the given Lua state / VM.
|
||||||
|
|
||||||
|
This includes all enabled standard libraries, which can
|
||||||
|
be used from Lua with `require("@lune/library-name")`.
|
||||||
|
|
||||||
|
# Errors
|
||||||
|
|
||||||
|
Errors when out of memory, or if *default* Lua globals are missing.
|
||||||
|
*/
|
||||||
|
pub fn inject_globals(lua: &Lua) -> LuaResult<()> {
|
||||||
|
for global in LuneStandardGlobal::ALL {
|
||||||
|
lua.globals().set(global.name(), global.create(lua)?)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
@ -3,20 +3,32 @@ use std::sync::Arc;
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
static VERSION_STRING: Lazy<Arc<String>> = Lazy::new(create_version_string);
|
static LUAU_VERSION: Lazy<Arc<String>> = Lazy::new(create_luau_version_string);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the current Lune version string, in the format `Lune x.y.z+luau`.
|
Returns a Lune version string, in the format `Lune x.y.z+luau`.
|
||||||
|
|
||||||
This version string is strongly guaranteed to follow the above
|
The version string passed should be the version of the Lune runtime,
|
||||||
format and may safely be used for parsing & version comparisons.
|
obtained from `env!("CARGO_PKG_VERSION")` or a similar mechanism.
|
||||||
|
|
||||||
|
# Panics
|
||||||
|
|
||||||
|
Panics if the version string is empty or contains invalid characters.
|
||||||
*/
|
*/
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_version_string() -> Arc<String> {
|
pub fn get_version_string(lune_version: impl AsRef<str>) -> String {
|
||||||
Arc::clone(&VERSION_STRING)
|
let lune_version = lune_version.as_ref();
|
||||||
|
|
||||||
|
assert!(!lune_version.is_empty(), "Lune version string is empty");
|
||||||
|
assert!(
|
||||||
|
lune_version.chars().all(is_valid_version_char),
|
||||||
|
"Lune version string contains invalid characters"
|
||||||
|
);
|
||||||
|
|
||||||
|
format!("Lune {lune_version}+{}", *LUAU_VERSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_version_string() -> Arc<String> {
|
fn create_luau_version_string() -> Arc<String> {
|
||||||
// Extract the current Luau version from a fresh Lua state / VM that can't be accessed externally.
|
// Extract the current Luau version from a fresh Lua state / VM that can't be accessed externally.
|
||||||
let luau_version_full = {
|
let luau_version_full = {
|
||||||
let temp_lua = Lua::new();
|
let temp_lua = Lua::new();
|
||||||
|
@ -55,10 +67,7 @@ fn create_version_string() -> Arc<String> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Arc::new(format!(
|
luau_version_noprefix.to_string().into()
|
||||||
"Lune {}+{luau_version_noprefix}",
|
|
||||||
env!("CARGO_PKG_VERSION")
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_valid_version_char(c: char) -> bool {
|
fn is_valid_version_char(c: char) -> bool {
|
||||||
|
|
Loading…
Add table
Reference in a new issue