made the lua app return the actual syntax error instead of "assertion failed!"
This commit is contained in:
+17
-4
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user