mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Use blocking io for print and warn globals
This commit is contained in:
parent
6f8b1e4896
commit
9c27057bf3
2 changed files with 10 additions and 26 deletions
|
@ -1,23 +1,15 @@
|
||||||
|
use std::io::Write as _;
|
||||||
|
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use tokio::{
|
|
||||||
io::{self, AsyncWriteExt},
|
|
||||||
task,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::lune::util::formatting::pretty_format_multi_value;
|
use crate::lune::util::formatting::pretty_format_multi_value;
|
||||||
|
|
||||||
pub fn create(lua: &Lua) -> LuaResult<impl IntoLua<'_>> {
|
pub fn create(lua: &Lua) -> LuaResult<impl IntoLua<'_>> {
|
||||||
lua.create_function(|_, args: LuaMultiValue| {
|
lua.create_function(|_, args: LuaMultiValue| {
|
||||||
let formatted = format!("{}\n", pretty_format_multi_value(&args)?);
|
let formatted = format!("{}\n", pretty_format_multi_value(&args)?);
|
||||||
task::spawn(async move {
|
let mut stdout = std::io::stdout();
|
||||||
let _res = async move {
|
stdout.write_all(formatted.as_bytes())?;
|
||||||
let mut stdout = io::stdout();
|
stdout.flush()?;
|
||||||
stdout.write_all(formatted.as_bytes()).await?;
|
|
||||||
stdout.flush().await?;
|
|
||||||
Ok::<_, LuaError>(())
|
|
||||||
};
|
|
||||||
// FUTURE: Send any error back to scheduler and emit it properly
|
|
||||||
});
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
|
use std::io::Write as _;
|
||||||
|
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use tokio::{
|
|
||||||
io::{self, AsyncWriteExt},
|
|
||||||
task,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::lune::util::formatting::{format_label, pretty_format_multi_value};
|
use crate::lune::util::formatting::{format_label, pretty_format_multi_value};
|
||||||
|
|
||||||
|
@ -13,15 +11,9 @@ pub fn create(lua: &Lua) -> LuaResult<impl IntoLua<'_>> {
|
||||||
format_label("warn"),
|
format_label("warn"),
|
||||||
pretty_format_multi_value(&args)?
|
pretty_format_multi_value(&args)?
|
||||||
);
|
);
|
||||||
task::spawn(async move {
|
let mut stderr = std::io::stderr();
|
||||||
let _res = async move {
|
stderr.write_all(formatted.as_bytes())?;
|
||||||
let mut stdout = io::stderr();
|
stderr.flush()?;
|
||||||
stdout.write_all(formatted.as_bytes()).await?;
|
|
||||||
stdout.flush().await?;
|
|
||||||
Ok::<_, LuaError>(())
|
|
||||||
};
|
|
||||||
// FUTURE: Send any error back to scheduler and emit it properly
|
|
||||||
});
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue