manen

Fancy Lua REPL
Log | Files | Refs | README | LICENSE

commit 1ad8c16cd509ae6ac8cd71f249520fc56262e6cc
parent af802166f141e2b4cb8fea618f6acd7feedab4a0
Author: Sylvia Ivory <git@sivory.net>
Date:   Wed,  2 Jul 2025 02:05:29 -0700

Add rc file support

Diffstat:
Msrc/config.rs | 30+++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/src/config.rs b/src/config.rs @@ -1,6 +1,6 @@ use directories::ProjectDirs; use mlua::prelude::*; -use std::{path::PathBuf, sync::Arc}; +use std::{fs, path::PathBuf, sync::Arc}; use crate::{ inspect::TableFormat, @@ -57,16 +57,36 @@ impl Config { } pub fn get_executor(&self) -> Result<Arc<dyn LuaExecutor>, SystemLuaError> { - match self.executor { - Executor::Embedded => Ok(Arc::new(MluaExecutor::new())), + let executor = match self.executor { + Executor::Embedded => Arc::new(MluaExecutor::new()), Executor::System => { if let Some(path) = &self.system_lua { - Ok(Arc::new(SystemLuaExecutor::new(&path.to_string_lossy())?)) + Arc::new(SystemLuaExecutor::new(&path.to_string_lossy())?) } else { - Ok(Arc::new(MluaExecutor::new())) + Arc::new(MluaExecutor::new()) as Arc<dyn LuaExecutor> } } + }; + + if let Some(proj_dirs) = ProjectDirs::from("net.sivory", "", "Manen") { + let config_dir = proj_dirs.config_dir(); + let rc_file = config_dir.join("rc.lua"); + + if rc_file.exists() { + let code = fs::read_to_string(rc_file)?; + + executor.exec(&code)?; + + let config = config_dir.to_string_lossy().to_string(); + executor.exec(&format!( + "if package and package.path then + package.path = package.path .. ';{config}/?.lua;{config}/?/init.lua' + end" + ))?; + } } + + Ok(executor) } }