From eea1c3155a188953008bbff031893aa8cb0610e9 Mon Sep 17 00:00:00 2001 From: Null Chilly <56817415+nullchilly@users.noreply.github.com> Date: Tue, 14 Mar 2023 23:41:45 +0700 Subject: [PATCH] feat(compiler): reduce bytecode size (#169) * feat(compiler): reduce bytecode size * added credits to nullchilly properly --------- Co-authored-by: Siduck siduck@tutanota.com> --- lua/base46/init.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lua/base46/init.lua b/lua/base46/init.lua index 848a5c6..de529c4 100644 --- a/lua/base46/init.lua +++ b/lua/base46/init.lua @@ -100,20 +100,18 @@ M.table_to_str = function(tb) end M.saveStr_to_cache = function(filename, tb) - -- Thanks to https://github.com/EdenEast/nightfox.nvim + -- Thanks to https://github.com/nullchilly and https://github.com/EdenEast/nightfox.nvim -- It helped me understand string.dump stuff local bg_opt = "vim.opt.bg='" .. M.get_theme_tb "type" .. "'" local defaults_cond = filename == "defaults" and bg_opt or "" local cache_path = vim.fn.stdpath "cache" .. "/nvchad/base46/" - local lines = 'require("base46").compiled = string.dump(function()' .. defaults_cond .. M.table_to_str(tb) .. "end)" + local lines = "return string.dump(function()" .. defaults_cond .. M.table_to_str(tb) .. "end, true)" local file = io.open(cache_path .. filename, "wb") - loadstring(lines, "=")() - if file then - file:write(require("base46").compiled) + file:write(loadstring(lines)()) file:close() end end @@ -182,7 +180,7 @@ M.toggle_theme = function() g.toggle_theme_icon = "  " require("nvchad").replace_word('theme = "' .. theme2, 'theme = "' .. theme1) end - + M.load_all_highlights() end