From 1db3a14c5426abce0e1e06b7b5dfbe8a0cb20533 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Wed, 15 Jan 2020 09:29:11 +0000 Subject: [PATCH] Eta-reduce several calls to pcall --- .../assets/computercraft/lua/bios.lua | 29 +++++++++---------- .../computercraft/lua/rom/programs/lua.lua | 2 +- .../lua/rom/programs/rednet/chat.lua | 16 +++++----- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/main/resources/assets/computercraft/lua/bios.lua b/src/main/resources/assets/computercraft/lua/bios.lua index 2913da090..500276da4 100644 --- a/src/main/resources/assets/computercraft/lua/bios.lua +++ b/src/main/resources/assets/computercraft/lua/bios.lua @@ -991,22 +991,19 @@ if fs.exists( ".settings" ) then end -- Run the shell -local ok, err = pcall( function() - parallel.waitForAny( - function() - local sShell - if term.isColour() and settings.get( "bios.use_multishell" ) then - sShell = "rom/programs/advanced/multishell.lua" - else - sShell = "rom/programs/shell.lua" - end - os.run( {}, sShell ) - os.run( {}, "rom/programs/shutdown.lua" ) - end, - function() - rednet.run() - end ) -end ) +local ok, err = pcall(parallel.waitForAny, + function() + local sShell + if term.isColour() and settings.get( "bios.use_multishell" ) then + sShell = "rom/programs/advanced/multishell.lua" + else + sShell = "rom/programs/shell.lua" + end + os.run( {}, sShell ) + os.run( {}, "rom/programs/shutdown.lua" ) + end, + rednet.run +) -- If the shell errored, let the user read it. term.redirect( term.native() ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua b/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua index 63d4c6add..0a6a664fe 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua @@ -10,7 +10,7 @@ local bRunning = true local tCommandHistory = {} local tEnv = { ["exit"] = setmetatable({}, { - __tostring = function() return "Call exit() to exit" end, + __tostring = function() return "Call exit() to exit." end, __call = function() bRunning = false end, }), ["_echo"] = function( ... ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua index 58a513f36..4c4ae75c0 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua @@ -105,8 +105,8 @@ if sCommand == "host" then end -- Handle messages - local ok, error = pcall( function() - parallel.waitForAny( function() + local ok, error = pcall(parallel.waitForAny, + function() while true do local _, timer = os.pullEvent( "timer" ) local nUserID = tPingPongTimer[ timer ] @@ -223,8 +223,8 @@ if sCommand == "host" then end end end - end ) - end ) + end + ) if not ok then printError( error ) end @@ -332,8 +332,8 @@ elseif sCommand == "join" then drawTitle() - local ok, error = pcall( function() - parallel.waitForAny( function() + local ok, error = pcall(parallel.waitForAny, + function() while true do local sEvent, timer = os.pullEvent() if sEvent == "timer" then @@ -402,8 +402,8 @@ elseif sCommand == "join" then table.insert( tSendHistory, sChat ) end end - end ) - end ) + end + ) -- Close the windows term.redirect( parentTerm )