mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-27 17:34:48 +00:00
Improve REPL's handling of expressions
- Remove the "force_print" code. This is a relic of before we used table.pack, and so didn't know how many expressions had been returned. - Check the input string is a valid expression separately before wrapping it in an _echo(...). Fixes #1506.
This commit is contained in:
parent
34f41c4039
commit
655d5aeca8
@ -74,18 +74,13 @@ while running do
|
|||||||
|
|
||||||
local name, offset = "=lua[" .. chunk_idx .. "]", 0
|
local name, offset = "=lua[" .. chunk_idx .. "]", 0
|
||||||
|
|
||||||
local force_print = 0
|
|
||||||
local func, err = load(input, name, "t", tEnv)
|
local func, err = load(input, name, "t", tEnv)
|
||||||
|
if load("return " .. input) then
|
||||||
local expr_func = load("return _echo(" .. input .. ");", name, "t", tEnv)
|
-- We wrap the expression with a call to _echo(...), which prevents tail
|
||||||
if not func then
|
-- calls (and thus confusing errors). Note we check this is a valid
|
||||||
if expr_func then
|
-- expression separately, to avoid accepting inputs like `)--` (which are
|
||||||
func = expr_func
|
-- parsed as `_echo()--)`.
|
||||||
offset = 13
|
func = load("return _echo(" .. input .. "\n)", name, "t", tEnv)
|
||||||
force_print = 1
|
|
||||||
end
|
|
||||||
elseif expr_func then
|
|
||||||
func = expr_func
|
|
||||||
offset = 13
|
offset = 13
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -96,7 +91,7 @@ while running do
|
|||||||
local results = table.pack(exception.try(func))
|
local results = table.pack(exception.try(func))
|
||||||
if results[1] then
|
if results[1] then
|
||||||
local n = 1
|
local n = 1
|
||||||
while n < results.n or n <= force_print do
|
while n < results.n do
|
||||||
local value = results[n + 1]
|
local value = results[n + 1]
|
||||||
local ok, serialised = pcall(pretty.pretty, value, {
|
local ok, serialised = pcall(pretty.pretty, value, {
|
||||||
function_args = settings.get("lua.function_args"),
|
function_args = settings.get("lua.function_args"),
|
||||||
|
Loading…
Reference in New Issue
Block a user