manen

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

commit aee2bf99f49e02cfc21ca6a421989826e8e807d8
parent a950776d8eb489cec38c2fc5c0dc2afa12e42ac6
Author: Sylvia Ivory <git@sivory.net>
Date:   Mon, 30 Jun 2025 17:26:54 -0700

Allow print to work in system Lua

Diffstat:
Msrc/lua.rs | 24+++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/lua.rs b/src/lua.rs @@ -114,16 +114,22 @@ impl SystemLuaExecutor { let cmd = command.to_lua(); process.send_line(&cmd)?; - let code = match process.read_line() { - Ok(code) => code, - Err(rexpect::error::Error::EOF { .. }) => { - *process = SendWrapper::new(Self::obtain_process(&self.program)?); - return Err(SystemLuaError::Restarted); + loop { + let code = match process.read_line() { + Ok(code) => code, + Err(rexpect::error::Error::EOF { .. }) => { + *process = SendWrapper::new(Self::obtain_process(&self.program)?); + return Err(SystemLuaError::Restarted); + } + x => x?, + }; + + if let Ok(res) = self.lua.load(&code).eval::<LuaTable>() { + return Ok(res); + } else { + println!("{}", &code); } - x => x?, - }; - - Ok(self.lua.load(code).eval()?) + } } }