mirror of
https://github.com/lune-org/lune.git
synced 2024-12-13 13:30:38 +00:00
Bring back version global
This commit is contained in:
parent
24b6498774
commit
7a63987cbe
2 changed files with 22 additions and 1 deletions
|
@ -4,10 +4,12 @@ use super::util::TableBuilder;
|
|||
|
||||
mod g_table;
|
||||
mod require;
|
||||
mod version;
|
||||
|
||||
pub fn inject_all(lua: &'static Lua) -> LuaResult<()> {
|
||||
let all = TableBuilder::new(lua)?
|
||||
.with_value("_G", g_table::create(lua)?)?
|
||||
.with_value("_VERSION", version::create(lua)?)?
|
||||
.with_value("require", require::create(lua)?)?
|
||||
.build_readonly()?;
|
||||
|
||||
|
|
|
@ -1,5 +1,24 @@
|
|||
use mlua::prelude::*;
|
||||
|
||||
pub fn create(lua: &'static Lua) -> LuaResult<impl IntoLua<'_>> {
|
||||
lua.create_table()
|
||||
let luau_version_full = lua
|
||||
.globals()
|
||||
.get::<_, LuaString>("_VERSION")
|
||||
.expect("Missing _VERSION global");
|
||||
|
||||
let luau_version = luau_version_full
|
||||
.to_str()?
|
||||
.strip_prefix("Luau 0.")
|
||||
.expect("_VERSION global is formatted incorrectly")
|
||||
.trim();
|
||||
|
||||
if luau_version.is_empty() {
|
||||
panic!("_VERSION global is missing version number")
|
||||
}
|
||||
|
||||
lua.create_string(format!(
|
||||
"Lune {lune}+{luau}",
|
||||
lune = env!("CARGO_PKG_VERSION"),
|
||||
luau = luau_version,
|
||||
))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue