From 8ab525b9ac36548443e81bb4caf849e6438c3843 Mon Sep 17 00:00:00 2001 From: Ponali Date: Mon, 20 Oct 2025 13:32:05 +0200 Subject: [PATCH] made the lua app return the actual syntax error instead of "assertion failed!" --- halyde/apps/lua.lua | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/halyde/apps/lua.lua b/halyde/apps/lua.lua index b0f7eb5..ccf2a03 100644 --- a/halyde/apps/lua.lua +++ b/halyde/apps/lua.lua @@ -48,13 +48,26 @@ print('Type "exit" to exit.') while true do local command = terminal.read("lua", "\27[44mlua>\27[0m ") if command == "exit" then + coroutine.yield() return elseif command ~= "" then local function runCommand() - local func = load("return " .. command, "=stdin") or load(command, "=stdin") - local res = { assert(func)() } - if res and (type(res[1]) ~= "nil" or type(res[2]) ~= "nil") then - print(table.unpack(res)) + local func, err = load("return " .. command, "=stdin") + local returns = true + if not func then + 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 local result, reason = xpcall(runCommand, function(errMsg)