mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
make standardlibrary object safe
This commit is contained in:
parent
2b7bb89037
commit
12b87b3065
3 changed files with 11 additions and 32 deletions
|
@ -1,8 +1,8 @@
|
||||||
|
use crate::{luaurc::path_to_alias, path::get_parent_path};
|
||||||
|
use mlua::prelude::*;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use mlua::prelude::*;
|
pub mod storage;
|
||||||
|
|
||||||
use crate::{luaurc::path_to_alias, path::get_parent_path};
|
|
||||||
|
|
||||||
pub async fn lua_require(lua: &Lua, path: String) -> LuaResult<LuaMultiValue> {
|
pub async fn lua_require(lua: &Lua, path: String) -> LuaResult<LuaMultiValue> {
|
||||||
let require_path_rel = PathBuf::from(path);
|
let require_path_rel = PathBuf::from(path);
|
||||||
|
|
6
crates/lune-std/src/globals/require/storage.rs
Normal file
6
crates/lune-std/src/globals/require/storage.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
use crate::library::StandardLibrary;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
pub struct RequireStorage<'a> {
|
||||||
|
stds: HashMap<&'a str, Box<dyn StandardLibrary>>,
|
||||||
|
}
|
|
@ -2,12 +2,7 @@ use std::str::FromStr;
|
||||||
|
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
|
|
||||||
pub trait StandardLibrary
|
pub trait StandardLibrary {
|
||||||
where
|
|
||||||
Self: Sized + 'static + FromStr,
|
|
||||||
{
|
|
||||||
const ALL: &'static [Self];
|
|
||||||
|
|
||||||
fn name(&self) -> &'static str;
|
fn name(&self) -> &'static str;
|
||||||
|
|
||||||
fn module<'lua>(&self, lua: &'lua Lua) -> LuaResult<LuaMultiValue<'lua>>;
|
fn module<'lua>(&self, lua: &'lua Lua) -> LuaResult<LuaMultiValue<'lua>>;
|
||||||
|
@ -32,23 +27,6 @@ pub enum LuneStandardLibrary {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StandardLibrary for LuneStandardLibrary {
|
impl StandardLibrary for LuneStandardLibrary {
|
||||||
/**
|
|
||||||
All available standard libraries.
|
|
||||||
*/
|
|
||||||
#[rustfmt::skip]
|
|
||||||
const ALL: &'static [Self] = &[
|
|
||||||
#[cfg(feature = "datetime")] Self::DateTime,
|
|
||||||
#[cfg(feature = "fs")] Self::Fs,
|
|
||||||
#[cfg(feature = "luau")] Self::Luau,
|
|
||||||
#[cfg(feature = "net")] Self::Net,
|
|
||||||
#[cfg(feature = "task")] Self::Task,
|
|
||||||
#[cfg(feature = "process")] Self::Process,
|
|
||||||
#[cfg(feature = "regex")] Self::Regex,
|
|
||||||
#[cfg(feature = "serde")] Self::Serde,
|
|
||||||
#[cfg(feature = "stdio")] Self::Stdio,
|
|
||||||
#[cfg(feature = "roblox")] Self::Roblox,
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gets the name of the library, such as `datetime` or `fs`.
|
Gets the name of the library, such as `datetime` or `fs`.
|
||||||
*/
|
*/
|
||||||
|
@ -125,12 +103,7 @@ impl FromStr for LuneStandardLibrary {
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"Unknown standard library '{low}'\nValid libraries are: {}",
|
"Unknown standard library '{low}'"
|
||||||
Self::ALL
|
|
||||||
.iter()
|
|
||||||
.map(Self::name)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ")
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue