mirror of
https://github.com/lune-org/lune.git
synced 2024-12-13 21:40:40 +00:00
Add back print and warn globals
This commit is contained in:
parent
029873fd5f
commit
9b4ca94c13
3 changed files with 40 additions and 1 deletions
|
@ -3,18 +3,22 @@ use mlua::prelude::*;
|
||||||
use super::util::TableBuilder;
|
use super::util::TableBuilder;
|
||||||
|
|
||||||
mod g_table;
|
mod g_table;
|
||||||
|
mod print;
|
||||||
mod require;
|
mod require;
|
||||||
mod version;
|
mod version;
|
||||||
|
mod warn;
|
||||||
|
|
||||||
pub fn inject_all(lua: &'static Lua) -> LuaResult<()> {
|
pub fn inject_all(lua: &'static Lua) -> LuaResult<()> {
|
||||||
let all = TableBuilder::new(lua)?
|
let all = TableBuilder::new(lua)?
|
||||||
.with_value("_G", g_table::create(lua)?)?
|
.with_value("_G", g_table::create(lua)?)?
|
||||||
.with_value("_VERSION", version::create(lua)?)?
|
.with_value("_VERSION", version::create(lua)?)?
|
||||||
|
.with_value("print", print::create(lua)?)?
|
||||||
.with_value("require", require::create(lua)?)?
|
.with_value("require", require::create(lua)?)?
|
||||||
|
.with_value("warn", warn::create(lua)?)?
|
||||||
.build_readonly()?;
|
.build_readonly()?;
|
||||||
|
|
||||||
for res in all.pairs() {
|
for res in all.pairs() {
|
||||||
let (key, value): (LuaValue, LuaValue) = res?;
|
let (key, value): (LuaValue, LuaValue) = res.unwrap();
|
||||||
lua.globals().set(key, value)?;
|
lua.globals().set(key, value)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
src/lune/globals/print.rs
Normal file
14
src/lune/globals/print.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
use mlua::prelude::*;
|
||||||
|
use tokio::io::{self, AsyncWriteExt};
|
||||||
|
|
||||||
|
use crate::lune::{scheduler::LuaSchedulerExt, util::formatting::pretty_format_multi_value};
|
||||||
|
|
||||||
|
pub fn create(lua: &'static Lua) -> LuaResult<impl IntoLua<'_>> {
|
||||||
|
lua.create_async_function(|_, args: LuaMultiValue| async move {
|
||||||
|
let formatted = format!("{}\n", pretty_format_multi_value(&args)?);
|
||||||
|
let mut stdout = io::stdout();
|
||||||
|
stdout.write_all(formatted.as_bytes()).await?;
|
||||||
|
stdout.flush().await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
21
src/lune/globals/warn.rs
Normal file
21
src/lune/globals/warn.rs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
use mlua::prelude::*;
|
||||||
|
use tokio::io::{self, AsyncWriteExt};
|
||||||
|
|
||||||
|
use crate::lune::{
|
||||||
|
scheduler::LuaSchedulerExt,
|
||||||
|
util::formatting::{format_label, pretty_format_multi_value},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn create(lua: &'static Lua) -> LuaResult<impl IntoLua<'_>> {
|
||||||
|
lua.create_async_function(|_, args: LuaMultiValue| async move {
|
||||||
|
let formatted = format!(
|
||||||
|
"{}\n{}",
|
||||||
|
format_label("warn"),
|
||||||
|
pretty_format_multi_value(&args)?
|
||||||
|
);
|
||||||
|
let mut stdout = io::stderr();
|
||||||
|
stdout.write_all(formatted.as_bytes()).await?;
|
||||||
|
stdout.flush().await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in a new issue