mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
fix: JSON value null should be deserialized as Lua nil, not lightweight userdata null (#2242)
This commit is contained in:
parent
abb43251fa
commit
cc568ee1fe
4 changed files with 10 additions and 12 deletions
|
|
@ -4,7 +4,7 @@ use yazi_config::{MANAGER, PREVIEW, THEME};
|
|||
|
||||
use super::Plugin;
|
||||
|
||||
const OPTIONS: SerializeOptions =
|
||||
pub const SER_OPTS: SerializeOptions =
|
||||
SerializeOptions::new().serialize_none_to_null(false).serialize_unit_to_null(false);
|
||||
|
||||
pub struct Config<'a> {
|
||||
|
|
@ -15,22 +15,22 @@ impl<'a> Config<'a> {
|
|||
pub fn new(lua: &'a Lua) -> Self { Self { lua } }
|
||||
|
||||
pub fn install_boot(self) -> mlua::Result<Self> {
|
||||
self.lua.globals().raw_set("BOOT", self.lua.to_value_with(&*BOOT, OPTIONS)?)?;
|
||||
self.lua.globals().raw_set("BOOT", self.lua.to_value_with(&*BOOT, SER_OPTS)?)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn install_manager(self) -> mlua::Result<Self> {
|
||||
self.lua.globals().raw_set("MANAGER", self.lua.to_value_with(&*MANAGER, OPTIONS)?)?;
|
||||
self.lua.globals().raw_set("MANAGER", self.lua.to_value_with(&*MANAGER, SER_OPTS)?)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn install_theme(self) -> mlua::Result<Self> {
|
||||
self.lua.globals().raw_set("THEME", self.lua.to_value_with(&*THEME, OPTIONS)?)?;
|
||||
self.lua.globals().raw_set("THEME", self.lua.to_value_with(&*THEME, SER_OPTS)?)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn install_preview(self) -> mlua::Result<Self> {
|
||||
self.lua.globals().raw_set("PREVIEW", self.lua.to_value_with(&*PREVIEW, OPTIONS)?)?;
|
||||
self.lua.globals().raw_set("PREVIEW", self.lua.to_value_with(&*PREVIEW, SER_OPTS)?)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,9 @@
|
|||
|
||||
mod macros;
|
||||
|
||||
yazi_macro::mod_pub!(
|
||||
bindings, elements, external, file, fs, isolate, loader, process, pubsub, url, utils
|
||||
);
|
||||
yazi_macro::mod_pub!(bindings config elements external file fs isolate loader process pubsub url utils);
|
||||
|
||||
yazi_macro::mod_flat!(clipboard config error lua runtime);
|
||||
yazi_macro::mod_flat!(clipboard error lua runtime);
|
||||
|
||||
pub fn init() -> anyhow::Result<()> {
|
||||
CLIPBOARD.with(<_>::default);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub(super) fn init_lua() -> Result<()> {
|
|||
|
||||
fn stage_1(lua: &'static Lua) -> Result<()> {
|
||||
lua.set_named_registry_value("rt", Runtime::default())?;
|
||||
crate::Config::new(lua).install_boot()?.install_manager()?.install_theme()?;
|
||||
crate::config::Config::new(lua).install_boot()?.install_manager()?.install_theme()?;
|
||||
|
||||
// Base
|
||||
let globals = lua.globals();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use mlua::{Function, IntoLuaMulti, Lua, LuaSerdeExt, Value};
|
||||
|
||||
use super::Utils;
|
||||
use crate::Error;
|
||||
use crate::{Error, config::SER_OPTS};
|
||||
|
||||
impl Utils {
|
||||
pub(super) fn json_encode(lua: &Lua) -> mlua::Result<Function> {
|
||||
|
|
@ -16,7 +16,7 @@ impl Utils {
|
|||
pub(super) fn json_decode(lua: &Lua) -> mlua::Result<Function> {
|
||||
lua.create_async_function(|lua, s: mlua::String| async move {
|
||||
match serde_json::from_slice::<serde_json::Value>(&s.as_bytes()) {
|
||||
Ok(v) => (lua.to_value(&v)?, Value::Nil).into_lua_multi(&lua),
|
||||
Ok(v) => (lua.to_value_with(&v, SER_OPTS)?, Value::Nil).into_lua_multi(&lua),
|
||||
Err(e) => (Value::Nil, Error::Serde(e)).into_lua_multi(&lua),
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue