Skip to content

Commit

Permalink
Serialize None to nil
Browse files Browse the repository at this point in the history
Fixes: #417
  • Loading branch information
sayanarijit committed Nov 19, 2021
1 parent 04dde7a commit 9ccdbc0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ use crate::app::VERSION;
use crate::config::Config;
use anyhow::bail;
use anyhow::Result;
use lazy_static::lazy_static;
use mlua::Lua;
use mlua::LuaSerdeExt;
use mlua::SerializeOptions;
use serde::Deserialize;
use std::fs;

const DEFAULT_LUA_SCRIPT: &str = include_str!("init.lua");
const CACHE_LUA_SCRIPT: &str = include_str!("__cache__.lua");
const UPGRADE_GUIDE_LINK: &str = "https://xplr.dev/en/upgrade-guide.html";

lazy_static! {
pub static ref SER_OPTIONS: SerializeOptions =
SerializeOptions::new().serialize_none_to_null(false);
}

fn parse_version(version: &str) -> Result<(u16, u16, u16, Option<u16>)> {
let mut configv = version.split('.');

Expand Down
3 changes: 2 additions & 1 deletion src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use anyhow::{bail, Error, Result};
use crossterm::event;
use crossterm::execute;
use crossterm::terminal as term;
use lua::SER_OPTIONS;
use mlua::LuaSerdeExt;
use std::fs;
use std::io::Write;
Expand All @@ -39,7 +40,7 @@ fn call_lua(
_silent: bool,
) -> Result<Option<Vec<app::ExternalMsg>>> {
let arg = app.to_lua_arg();
let arg = lua.to_value(&arg)?;
let arg = lua.to_value_with(&arg, SER_OPTIONS.clone())?;
lua::call_with_cache(lua, func, arg)
}

Expand Down
11 changes: 7 additions & 4 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,10 @@ fn draw_table<B: Backend>(
);

let cols = lua
.to_value::<NodeUiMetadata>(&meta)
.to_value_with::<NodeUiMetadata>(
&meta,
lua::SER_OPTIONS.clone(),
)
.map(|v| {
app_config
.general
Expand Down Expand Up @@ -1040,7 +1043,7 @@ pub fn draw_custom_content<B: Backend>(
};

let render = lua
.to_value(&ctx)
.to_value_with(&ctx, lua::SER_OPTIONS.clone())
.map(|arg| {
lua::call_with_cache(lua, &render, arg)
.unwrap_or_else(|e| format!("{:?}", e))
Expand Down Expand Up @@ -1082,7 +1085,7 @@ pub fn draw_custom_content<B: Backend>(
};

let items = lua
.to_value(&ctx)
.to_value_with(&ctx, lua::SER_OPTIONS.clone())
.map(|arg| {
lua::call_with_cache(lua, &render, arg)
.unwrap_or_else(|e| vec![format!("{:?}", e)])
Expand Down Expand Up @@ -1152,7 +1155,7 @@ pub fn draw_custom_content<B: Backend>(
};

let rows = lua
.to_value(&ctx)
.to_value_with(&ctx, lua::SER_OPTIONS.clone())
.map(|arg| {
lua::call_with_cache(lua, &render, arg)
.unwrap_or_else(|e| vec![vec![format!("{:?}", e)]])
Expand Down

0 comments on commit 9ccdbc0

Please sign in to comment.