manen

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

commit af802166f141e2b4cb8fea618f6acd7feedab4a0
parent c549527d7bb916dd62f4afac4010c7b0d16bf194
Author: Sylvia Ivory <git@sivory.net>
Date:   Wed,  2 Jul 2025 01:47:08 -0700

Allow multiline input with system Lua

Diffstat:
Mlua/rpc.lua | 8+++-----
Msrc/lua.rs | 4+++-
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lua/rpc.lua b/lua/rpc.lua @@ -232,13 +232,11 @@ function rpc.globals() rpc.respond('globals', _G) end -local loadstring_luas = { - ['Lua 5.1'] = true, - ['Luau'] = true, -} +local load_fn = _VERSION == 'Lua 5.1' and loadstring or load function rpc.exec(code) - local load_fn = loadstring_luas[_VERSION] and loadstring or load + code = load_fn('return ' .. code)() + local fn = load_fn(code, 'repl') if not fn then diff --git a/src/lua.rs b/src/lua.rs @@ -17,6 +17,8 @@ use send_wrapper::SendWrapper; use tempfile::NamedTempFile; use thiserror::Error; +use crate::inspect::format_string_bytes; + pub trait LuaExecutor: Send + Sync { fn exec(&self, code: &str) -> LuaResult<LuaValue>; fn globals(&self) -> LuaResult<LuaTable>; @@ -96,7 +98,7 @@ impl RpcCommand { pub fn to_lua(&self) -> String { match self { Self::Globals => String::from("globals"), - Self::Exec(code) => format!("exec:{code}"), + Self::Exec(code) => format!("exec:{}", format_string_bytes(code.as_bytes(), false)), Self::Prepare(file) => format!("prepare:{file}"), } }