made the lua app return the actual syntax error instead of "assertion failed!"

This commit is contained in:
Ponali
2025-10-20 13:32:05 +02:00
parent 245b6a524d
commit 8ab525b9ac
+17 -4
View File
@@ -48,13 +48,26 @@ print('Type "exit" to exit.')
while true do while true do
local command = terminal.read("lua", "\27[44mlua>\27[0m ") local command = terminal.read("lua", "\27[44mlua>\27[0m ")
if command == "exit" then if command == "exit" then
coroutine.yield()
return return
elseif command ~= "" then elseif command ~= "" then
local function runCommand() local function runCommand()
local func = load("return " .. command, "=stdin") or load(command, "=stdin") local func, err = load("return " .. command, "=stdin")
local res = { assert(func)() } local returns = true
if res and (type(res[1]) ~= "nil" or type(res[2]) ~= "nil") then if not func then
print(table.unpack(res)) func, err = load(command, "=stdin")
returns = false
end
if not func then
return print("\x1b[91msyntax error: " .. (err or "unknown error"))
end
local res = { func() }
if returns then
if res and type(res[1]) ~= "nil" then
print(table.unpack(res))
elseif res and type(res[2]) ~= "nil" then
print("nil", table.unpack(res))
end
end end
end end
local result, reason = xpcall(runCommand, function(errMsg) local result, reason = xpcall(runCommand, function(errMsg)