mirror of
https://github.com/lune-org/lune.git
synced 2025-01-05 19:09:10 +00:00
Fix print and warn globals yielding
This commit is contained in:
parent
0e54d7f124
commit
cd78fea1f5
3 changed files with 33 additions and 17 deletions
|
@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed the `print` and `warn` global functions yielding the thread, preventing them from being used in places such as the callback to `table.sort`.
|
||||||
- Fixed the `overwrite` option for `fs.move` not correctly removing existing files / directories. ([#133])
|
- Fixed the `overwrite` option for `fs.move` not correctly removing existing files / directories. ([#133])
|
||||||
|
|
||||||
[#133]: https://github.com/filiptibell/lune/pull/133
|
[#133]: https://github.com/filiptibell/lune/pull/133
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use tokio::io::{self, AsyncWriteExt};
|
use tokio::{
|
||||||
|
io::{self, AsyncWriteExt},
|
||||||
|
task,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::lune::{scheduler::LuaSchedulerExt, util::formatting::pretty_format_multi_value};
|
use crate::lune::util::formatting::pretty_format_multi_value;
|
||||||
|
|
||||||
pub fn create(lua: &'static Lua) -> LuaResult<impl IntoLua<'_>> {
|
pub fn create(lua: &Lua) -> LuaResult<impl IntoLua<'_>> {
|
||||||
lua.create_async_function(|_, args: LuaMultiValue| async move {
|
lua.create_function(|_, args: LuaMultiValue| {
|
||||||
let formatted = format!("{}\n", pretty_format_multi_value(&args)?);
|
let formatted = format!("{}\n", pretty_format_multi_value(&args)?);
|
||||||
let mut stdout = io::stdout();
|
task::spawn(async move {
|
||||||
stdout.write_all(formatted.as_bytes()).await?;
|
let _res = async move {
|
||||||
stdout.flush().await?;
|
let mut stdout = io::stdout();
|
||||||
|
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,21 +1,27 @@
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use tokio::io::{self, AsyncWriteExt};
|
use tokio::{
|
||||||
|
io::{self, AsyncWriteExt},
|
||||||
use crate::lune::{
|
task,
|
||||||
scheduler::LuaSchedulerExt,
|
|
||||||
util::formatting::{format_label, pretty_format_multi_value},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn create(lua: &'static Lua) -> LuaResult<impl IntoLua<'_>> {
|
use crate::lune::util::formatting::{format_label, pretty_format_multi_value};
|
||||||
lua.create_async_function(|_, args: LuaMultiValue| async move {
|
|
||||||
|
pub fn create(lua: &Lua) -> LuaResult<impl IntoLua<'_>> {
|
||||||
|
lua.create_function(|_, args: LuaMultiValue| {
|
||||||
let formatted = format!(
|
let formatted = format!(
|
||||||
"{}\n{}\n",
|
"{}\n{}\n",
|
||||||
format_label("warn"),
|
format_label("warn"),
|
||||||
pretty_format_multi_value(&args)?
|
pretty_format_multi_value(&args)?
|
||||||
);
|
);
|
||||||
let mut stdout = io::stderr();
|
task::spawn(async move {
|
||||||
stdout.write_all(formatted.as_bytes()).await?;
|
let _res = async move {
|
||||||
stdout.flush().await?;
|
let mut stdout = io::stderr();
|
||||||
|
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