From 86e0330100ca34692a06f04a743970a9a062db1f Mon Sep 17 00:00:00 2001 From: SquidDev Date: Tue, 3 Dec 2019 23:26:13 +0000 Subject: [PATCH] Lint bios and the rom (#321) We now use illuaminate[1]'s linting facilities to check the rom and bios.lua for a couple of common bugs and other problems. Right now this doesn't detect any especially important bugs, though it has caught lots of small things (unused variables, some noisy code). In the future, the linter will grow in scope and features, which should allow us to be stricter and catch most issues. As a fun aside, we started off with ~150 bugs, and illuaminate was able to fix all but 30 of them, which is pretty neat. [1]: https://github.com/SquidDev/illuaminate --- .editorconfig | 3 ++ .github/workflows/main-ci.yml | 15 +++++++++ illuaminate.sexp | 25 +++++++++++++++ .../assets/computercraft/lua/bios.lua | 26 ++++++++-------- .../lua/rom/apis/command/commands.lua | 4 +-- .../computercraft/lua/rom/apis/disk.lua | 2 +- .../assets/computercraft/lua/rom/apis/gps.lua | 10 +++--- .../computercraft/lua/rom/apis/help.lua | 4 +-- .../computercraft/lua/rom/apis/paintutils.lua | 4 +-- .../computercraft/lua/rom/apis/peripheral.lua | 16 +++++----- .../computercraft/lua/rom/apis/rednet.lua | 10 +++--- .../computercraft/lua/rom/apis/settings.lua | 2 +- .../computercraft/lua/rom/apis/term.lua | 2 +- .../computercraft/lua/rom/apis/textutils.lua | 16 +++++----- .../computercraft/lua/rom/apis/vector.lua | 6 ++-- .../computercraft/lua/rom/apis/window.lua | 2 +- .../lua/rom/programs/advanced/multishell.lua | 7 ++--- .../computercraft/lua/rom/programs/copy.lua | 2 +- .../computercraft/lua/rom/programs/delete.lua | 2 +- .../computercraft/lua/rom/programs/drive.lua | 4 +-- .../computercraft/lua/rom/programs/edit.lua | 11 +++---- .../lua/rom/programs/fun/advanced/paint.lua | 6 ++-- .../rom/programs/fun/advanced/redirection.lua | 10 +++--- .../lua/rom/programs/fun/adventure.lua | 31 +++++++++---------- .../computercraft/lua/rom/programs/fun/dj.lua | 2 +- .../lua/rom/programs/fun/worm.lua | 11 ++----- .../computercraft/lua/rom/programs/gps.lua | 4 +-- .../computercraft/lua/rom/programs/help.lua | 2 +- .../computercraft/lua/rom/programs/list.lua | 2 +- .../computercraft/lua/rom/programs/lua.lua | 4 +-- .../computercraft/lua/rom/programs/move.lua | 2 +- .../lua/rom/programs/pocket/falling.lua | 11 +++---- .../lua/rom/programs/rednet/chat.lua | 15 +++++---- .../lua/rom/programs/rednet/repeat.lua | 4 +-- .../lua/rom/programs/redstone.lua | 6 ++-- .../computercraft/lua/rom/programs/set.lua | 2 +- .../computercraft/lua/rom/programs/shell.lua | 12 +++---- .../lua/rom/programs/turtle/dance.lua | 4 +-- .../lua/rom/programs/turtle/excavate.lua | 9 +++--- .../lua/rom/programs/turtle/refuel.lua | 2 +- .../lua/rom/programs/turtle/tunnel.lua | 2 -- .../lua/rom/programs/turtle/turn.lua | 2 +- .../assets/computercraft/lua/rom/startup.lua | 2 +- 43 files changed, 173 insertions(+), 145 deletions(-) create mode 100644 illuaminate.sexp diff --git a/.editorconfig b/.editorconfig index f04c87852..f11468850 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,5 +11,8 @@ insert_final_newline = true [*.md] trim_trailing_whitespace = false +[*.sexp] +indent_size = 2 + [*.properties] insert_final_newline = false diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml index 16f34b3e2..0be633a53 100644 --- a/.github/workflows/main-ci.yml +++ b/.github/workflows/main-ci.yml @@ -4,6 +4,7 @@ on: [push, pull_request] jobs: build: + name: Build runs-on: ubuntu-latest steps: @@ -16,3 +17,17 @@ jobs: - name: Build with Gradle run: ./gradlew build --no-daemon + + lint-lua: + name: Lint Lua + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: Lint Lua code + run: | + test -d bin || mkdir bin + test -f bin/illuaminate || wget -q -Obin/illuaminate https://squiddev.cc/illuaminate/bin/illuaminate + chmod +x bin/illuaminate + GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/illuaminate lint --github diff --git a/illuaminate.sexp b/illuaminate.sexp new file mode 100644 index 000000000..2271a01e5 --- /dev/null +++ b/illuaminate.sexp @@ -0,0 +1,25 @@ +; -*- mode: Lisp;-*- + +(sources + /src/main/resources/assets/computercraft/lua/bios.lua + /src/main/resources/assets/computercraft/lua/rom/) + +(at / + (linters + ;; It'd be nice to avoid this, but right now there's a lot of instances of it. + -var:set-loop + + ;; It's useful to name arguments for documentation, so we allow this. It'd + ;; be good to find a compromise in the future, but this works for now. + -var:unused-arg)) + +;; We disable the two global linters in bios.lua and the APIs. In the future +;; hopefully we'll get illuaminate to handle this. +(at + (/src/main/resources/assets/computercraft/lua/bios.lua + /src/main/resources/assets/computercraft/lua/rom/apis/) + (linters -var:set-global -var:unused-global)) + +;; These warnings are broken right now +(at completion.lua (linters -doc:malformed-type)) +(at (bios.lua worm.lua) (linters -control:unreachable)) diff --git a/src/main/resources/assets/computercraft/lua/bios.lua b/src/main/resources/assets/computercraft/lua/bios.lua index cebfe1fa3..e4b792538 100644 --- a/src/main/resources/assets/computercraft/lua/bios.lua +++ b/src/main/resources/assets/computercraft/lua/bios.lua @@ -184,7 +184,7 @@ function sleep( nTime ) expect(1, nTime, "number", "nil") local timer = os.startTimer( nTime or 0 ) repeat - local sEvent, param = os.pullEvent( "timer" ) + local _, param = os.pullEvent( "timer" ) until param == timer end @@ -233,7 +233,7 @@ function write( sText ) newLine() end term.write( text ) - text = string.sub( text, (w-x) + 2 ) + text = string.sub( text, w-x + 2 ) x,y = term.getCursorPos() end else @@ -332,7 +332,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault ) local _, cy = term.getCursorPos() term.setCursorPos( sx, cy ) - local sReplace = (_bClear and " ") or _sReplaceChar + local sReplace = _bClear and " " or _sReplaceChar if sReplace then term.write( string.rep( sReplace, math.max( #sLine - nScroll, 0 ) ) ) else @@ -544,7 +544,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault ) end end - local cx, cy = term.getCursorPos() + local _, cy = term.getCursorPos() term.setCursorBlink( false ) term.setCursorPos( w + 1, cy ) print() @@ -775,7 +775,7 @@ if http then if not ok then return ok, err end while true do - local event, url, ok, err = os.pullEvent( "http_check" ) + local _, url, ok, err = os.pullEvent( "http_check" ) if url == _url then return ok, err end end end @@ -808,8 +808,8 @@ function fs.complete( sPath, sLocation, bIncludeFiles, bIncludeDirs ) expect(3, bIncludeFiles, "boolean", "nil") expect(4, bIncludeDirs, "boolean", "nil") - bIncludeFiles = (bIncludeFiles ~= false) - bIncludeDirs = (bIncludeDirs ~= false) + bIncludeFiles = bIncludeFiles ~= false + bIncludeDirs = bIncludeDirs ~= false local sDir = sLocation local nStart = 1 local nSlash = string.find( sPath, "[/\\]", nStart ) @@ -836,9 +836,9 @@ function fs.complete( sPath, sLocation, bIncludeFiles, bIncludeDirs ) end if sDir ~= "" then if sPath == "" then - table.insert( tResults, (bIncludeDirs and "..") or "../" ) + table.insert( tResults, bIncludeDirs and ".." or "../" ) elseif sPath == "." then - table.insert( tResults, (bIncludeDirs and ".") or "./" ) + table.insert( tResults, bIncludeDirs and "." or "./" ) end end local tFiles = fs.list( sDir ) @@ -867,7 +867,7 @@ end -- Load APIs local bAPIError = false local tApis = fs.list( "rom/apis" ) -for n,sFile in ipairs( tApis ) do +for _,sFile in ipairs( tApis ) do if string.sub( sFile, 1, 1 ) ~= "." then local sPath = fs.combine( "rom/apis", sFile ) if not fs.isDir( sPath ) then @@ -881,7 +881,7 @@ end if turtle and fs.isDir( "rom/apis/turtle" ) then -- Load turtle APIs local tApis = fs.list( "rom/apis/turtle" ) - for n,sFile in ipairs( tApis ) do + for _,sFile in ipairs( tApis ) do if string.sub( sFile, 1, 1 ) ~= "." then local sPath = fs.combine( "rom/apis/turtle", sFile ) if not fs.isDir( sPath ) then @@ -896,7 +896,7 @@ end if pocket and fs.isDir( "rom/apis/pocket" ) then -- Load pocket APIs local tApis = fs.list( "rom/apis/pocket" ) - for n,sFile in ipairs( tApis ) do + for _,sFile in ipairs( tApis ) do if string.sub( sFile, 1, 1 ) ~= "." then local sPath = fs.combine( "rom/apis/pocket", sFile ) if not fs.isDir( sPath ) then @@ -946,7 +946,7 @@ end -- Set default settings settings.set( "shell.allow_startup", true ) -settings.set( "shell.allow_disk_startup", (commands == nil) ) +settings.set( "shell.allow_disk_startup", commands == nil ) settings.set( "shell.autocomplete", true ) settings.set( "edit.autocomplete", true ) settings.set( "edit.default_extension", "lua" ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/command/commands.lua b/src/main/resources/assets/computercraft/lua/rom/apis/command/commands.lua index 849bf8e7c..7afd34bad 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/command/commands.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/command/commands.lua @@ -33,9 +33,9 @@ local tNonNBTJSONCommands = { [ "title" ] = true } local tCommands = native.list() -for n,sCommandName in ipairs(tCommands) do +for _,sCommandName in ipairs(tCommands) do if env[ sCommandName ] == nil then - local bJSONIsNBT = (tNonNBTJSONCommands[ sCommandName ] == nil) + local bJSONIsNBT = tNonNBTJSONCommands[ sCommandName ] == nil env[ sCommandName ] = function( ... ) local sCommand = collapseArgs( bJSONIsNBT, sCommandName, ... ) return native.exec( sCommand ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua b/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua index 637a48b07..2c5e6ec8b 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua @@ -62,7 +62,7 @@ end function stopAudio( name ) if not name then - for n,sName in ipairs( peripheral.getNames() ) do + for _,sName in ipairs( peripheral.getNames() ) do stopAudio( sName ) end else diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua b/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua index 08f698eb2..aab023209 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua @@ -13,7 +13,7 @@ local function trilaterate( A, B, C ) local d = a2b:length() local ex = a2b:normalize( ) local i = ex:dot( a2c ) - local ey = (a2c - (ex * i)):normalize() + local ey = (a2c - ex * i):normalize() local j = ey:dot( a2c ) local ez = ex:cross( ey ) @@ -24,13 +24,13 @@ local function trilaterate( A, B, C ) local x = (r1*r1 - r2*r2 + d*d) / (2*d) local y = (r1*r1 - r3*r3 - x*x + (x-i)*(x-i) + j*j) / (2*j) - local result = A.vPosition + (ex * x) + (ey * y) + local result = A.vPosition + ex * x + ey * y local zSquared = r1*r1 - x*x - y*y if zSquared > 0 then local z = math.sqrt( zSquared ) - local result1 = result + (ez * z) - local result2 = result - (ez * z) + local result1 = result + ez * z + local result2 = result - ez * z local rounded1, rounded2 = result1:round( 0.01 ), result2:round( 0.01 ) if rounded1.x ~= rounded2.x or rounded1.y ~= rounded2.y or rounded1.z ~= rounded2.z then @@ -66,7 +66,7 @@ function locate( _nTimeout, _bDebug ) -- Find a modem local sModemSide = nil - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then sModemSide = sSide break diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/help.lua b/src/main/resources/assets/computercraft/lua/rom/apis/help.lua index b4e69921f..853ec09a0 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/help.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/help.lua @@ -37,7 +37,7 @@ function topics() for sPath in string.gmatch(sPath, "[^:]+") do if fs.isDir( sPath ) then local tList = fs.list( sPath ) - for n,sFile in pairs( tList ) do + for _,sFile in pairs( tList ) do if string.sub( sFile, 1, 1 ) ~= "." then if not fs.isDir( fs.combine( sPath, sFile ) ) then if #sFile > 4 and sFile:sub(-4) == ".txt" then @@ -52,7 +52,7 @@ function topics() -- Sort and return local tItemList = {} - for sItem, b in pairs( tItems ) do + for sItem in pairs( tItems ) do table.insert( tItemList, sItem ) end table.sort( tItemList ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua b/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua index 0988945e0..5420b029d 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua @@ -147,8 +147,8 @@ function drawBox( startX, startY, endX, endY, nColour ) drawPixelInternal( x, maxY ) end - if (maxY - minY) >= 2 then - for y=(minY+1),(maxY-1) do + if maxY - minY >= 2 then + for y=minY+1,maxY-1 do drawPixelInternal( minX, y ) drawPixelInternal( maxX, y ) end diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua b/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua index 3f4fdc150..ecfccbb53 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua @@ -4,12 +4,12 @@ local native = peripheral function getNames() local tResults = {} - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if native.isPresent( sSide ) then table.insert( tResults, sSide ) if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then local tRemote = native.call( sSide, "getNamesRemote" ) - for n,sName in ipairs( tRemote ) do + for _,sName in ipairs( tRemote ) do table.insert( tResults, sName ) end end @@ -23,7 +23,7 @@ function isPresent( _sSide ) if native.isPresent( _sSide ) then return true end - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.call( sSide, "isPresentRemote", _sSide ) then return true @@ -38,7 +38,7 @@ function getType( _sSide ) if native.isPresent( _sSide ) then return native.getType( _sSide ) end - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.call( sSide, "isPresentRemote", _sSide ) then return native.call( sSide, "getTypeRemote", _sSide ) @@ -53,7 +53,7 @@ function getMethods( _sSide ) if native.isPresent( _sSide ) then return native.getMethods( _sSide ) end - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.call( sSide, "isPresentRemote", _sSide ) then return native.call( sSide, "getMethodsRemote", _sSide ) @@ -69,7 +69,7 @@ function call( _sSide, _sMethod, ... ) if native.isPresent( _sSide ) then return native.call( _sSide, _sMethod, ... ) end - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.call( sSide, "isPresentRemote", _sSide ) then return native.call( sSide, "callRemote", _sSide, _sMethod, ... ) @@ -84,7 +84,7 @@ function wrap( _sSide ) if peripheral.isPresent( _sSide ) then local tMethods = peripheral.getMethods( _sSide ) local tResult = {} - for n,sMethod in ipairs( tMethods ) do + for _,sMethod in ipairs( tMethods ) do tResult[sMethod] = function( ... ) return peripheral.call( _sSide, sMethod, ... ) end @@ -98,7 +98,7 @@ function find( sType, fnFilter ) expect(1, sType, "string") expect(2, fnFilter, "function", "nil") local tResults = {} - for n,sName in ipairs( peripheral.getNames() ) do + for _,sName in ipairs( peripheral.getNames() ) do if peripheral.getType( sName ) == sType then local wrapped = peripheral.wrap( sName ) if fnFilter == nil or fnFilter( sName, wrapped ) then diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua b/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua index 5af3a4706..e38084ad5 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua @@ -27,7 +27,7 @@ function close( sModem ) peripheral.call( sModem, "close", CHANNEL_BROADCAST ) else -- Close all modems - for n,sModem in ipairs( peripheral.getNames() ) do + for _,sModem in ipairs( peripheral.getNames() ) do if isOpen( sModem ) then close( sModem ) end @@ -44,7 +44,7 @@ function isOpen( sModem ) end else -- Check if any modem is open - for n,sModem in ipairs( peripheral.getNames() ) do + for _,sModem in ipairs( peripheral.getNames() ) do if isOpen( sModem ) then return true end @@ -79,10 +79,10 @@ function send( nRecipient, message, sProtocol ) sent = true else -- Send on all open modems, to the target and to repeaters - for n,sModem in ipairs( peripheral.getNames() ) do + for _,sModem in ipairs( peripheral.getNames() ) do if isOpen( sModem ) then - peripheral.call( sModem, "transmit", nRecipient, nReplyChannel, tMessage ); - peripheral.call( sModem, "transmit", CHANNEL_REPEAT, nReplyChannel, tMessage ); + peripheral.call( sModem, "transmit", nRecipient, nReplyChannel, tMessage ) + peripheral.call( sModem, "transmit", CHANNEL_REPEAT, nReplyChannel, tMessage ) sent = true end end diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua b/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua index d60510937..9f9ba9822 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua @@ -47,7 +47,7 @@ end function getNames() local result = {} - for k,v in pairs( tSettings ) do + for k in pairs( tSettings ) do result[ #result + 1 ] = k end table.sort(result) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/term.lua b/src/main/resources/assets/computercraft/lua/rom/apis/term.lua index e9ad00408..98db90be7 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/term.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/term.lua @@ -1,6 +1,6 @@ local expect = dofile("rom/modules/main/cc/expect.lua").expect -local native = (term.native and term.native()) or term +local native = term.native and term.native() or term local redirectTarget = native local function wrap( _sFunction ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua b/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua index 447babb44..09130fbad 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua @@ -16,7 +16,7 @@ function slowWrite( sText, nRate ) term.setCursorPos( x, y ) sleep( nSleep ) local nLines = write( string.sub( sText, 1, n ) ) - local newX, newY = term.getCursorPos() + local _, newY = term.getCursorPos() y = newY - nLines end end @@ -54,11 +54,11 @@ local function makePagedScroll( _term, _nFreeLines ) local nativeScroll = _term.scroll local nFreeLines = _nFreeLines or 0 return function( _n ) - for n=1,_n do + for _=1,_n do nativeScroll( 1 ) if nFreeLines <= 0 then - local w,h = _term.getSize() + local _,h = _term.getSize() _term.setCursorPos( 1, h ) _term.write( "Press any key to continue" ) os.pullEvent( "key" ) @@ -123,7 +123,7 @@ local function tabulateCommon( bPaged, ... ) local nCols = math.floor( w / nMaxLen ) local nLines = 0 local function newLine() - if bPaged and nLines >= (h-3) then + if bPaged and nLines >= h-3 then pagedPrint() else print() @@ -133,14 +133,14 @@ local function tabulateCommon( bPaged, ... ) local function drawCols( _t ) local nCol = 1 - for n, s in ipairs( _t ) do + for _, s in ipairs( _t ) do if nCol > nCols then nCol = 1 newLine() end local cx, cy = term.getCursorPos() - cx = 1 + ((nCol - 1) * nMaxLen) + cx = 1 + (nCol - 1) * nMaxLen term.setCursorPos( cx, cy ) term.write( s ) @@ -148,7 +148,7 @@ local function tabulateCommon( bPaged, ... ) end print() end - for n, t in ipairs( tAll ) do + for _, t in ipairs( tAll ) do if type(t) == "table" then if #t > 0 then drawCols( t ) @@ -280,7 +280,7 @@ local function serializeJSONImpl( t, tTracking, bNBTStyle ) nObjectSize = nObjectSize + 1 end end - for n,v in ipairs(t) do + for _,v in ipairs(t) do local sEntry = serializeJSONImpl( v, tTracking, bNBTStyle ) if nArraySize == 0 then sArrayResult = sArrayResult .. sEntry diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua b/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua index 2fd2fbdb6..7a6db14b7 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua @@ -54,9 +54,9 @@ local vector = { round = function( self, nTolerance ) nTolerance = nTolerance or 1.0 return vector.new( - math.floor( (self.x + (nTolerance * 0.5)) / nTolerance ) * nTolerance, - math.floor( (self.y + (nTolerance * 0.5)) / nTolerance ) * nTolerance, - math.floor( (self.z + (nTolerance * 0.5)) / nTolerance ) * nTolerance + math.floor( (self.x + nTolerance * 0.5) / nTolerance ) * nTolerance, + math.floor( (self.y + nTolerance * 0.5) / nTolerance ) * nTolerance, + math.floor( (self.z + nTolerance * 0.5) / nTolerance ) * nTolerance ) end, tostring = function( self ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/window.lua b/src/main/resources/assets/computercraft/lua/rom/apis/window.lua index 87ede5cbd..2f20220fc 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/window.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/window.lua @@ -49,7 +49,7 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) createEmptyLines( nWidth ) -- Setup - local bVisible = (bStartVisible ~= false) + local bVisible = bStartVisible ~= false local nCursorX = 1 local nCursorY = 1 local bCursorBlink = false diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua b/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua index 51c1c1753..b07cccf3c 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua @@ -172,7 +172,6 @@ local function resizeWindows() end for n=1,#tProcesses do local tProcess = tProcesses[n] - local window = tProcess.window local x,y = tProcess.window.getCursorPos() if y > windowHeight then tProcess.window.scroll( y - windowHeight ) @@ -232,7 +231,7 @@ function multishell.launch( tProgramEnv, sProgramPath, ... ) expect(1, tProgramEnv, "table") expect(2, sProgramPath, "string") local previousTerm = term.current() - setMenuVisible( (#tProcesses + 1) >= 2 ) + setMenuVisible( #tProcesses + 1 >= 2 ) local nResult = launchProcess( false, tProgramEnv, sProgramPath, ... ) redrawMenu() term.redirect( previousTerm ) @@ -299,7 +298,7 @@ while #tProcesses > 0 do end else -- Passthrough to current process - resumeProcess( nCurrentProcess, sEvent, button, x, (bShowMenu and y-1) or y ) + resumeProcess( nCurrentProcess, sEvent, button, x, bShowMenu and y-1 or y ) if cullProcess( nCurrentProcess ) then setMenuVisible( #tProcesses >= 2 ) redrawMenu() @@ -319,7 +318,7 @@ while #tProcesses > 0 do end elseif not (bShowMenu and y == 1) then -- Passthrough to current process - resumeProcess( nCurrentProcess, sEvent, p1, x, (bShowMenu and y-1) or y ) + resumeProcess( nCurrentProcess, sEvent, p1, x, bShowMenu and y-1 or y ) if cullProcess( nCurrentProcess ) then setMenuVisible( #tProcesses >= 2 ) redrawMenu() diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/copy.lua b/src/main/resources/assets/computercraft/lua/rom/programs/copy.lua index 70cde52a1..71ea68043 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/copy.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/copy.lua @@ -9,7 +9,7 @@ local sSource = shell.resolve( tArgs[1] ) local sDest = shell.resolve( tArgs[2] ) local tFiles = fs.find( sSource ) if #tFiles > 0 then - for n,sFile in ipairs( tFiles ) do + for _,sFile in ipairs( tFiles ) do if fs.isDir( sDest ) then fs.copy( sFile, fs.combine( sDest, fs.getName(sFile) ) ) elseif #tFiles == 1 then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/delete.lua b/src/main/resources/assets/computercraft/lua/rom/programs/delete.lua index e2d296805..91f2e0c23 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/delete.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/delete.lua @@ -8,7 +8,7 @@ end for i = 1, args.n do local files = fs.find(shell.resolve(args[i])) if #files > 0 then - for n, file in ipairs(files) do + for _, file in ipairs(files) do local ok, err = pcall(fs.delete, file) if not ok then printError((err:gsub("^pcall: ", ""))) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/drive.lua b/src/main/resources/assets/computercraft/lua/rom/programs/drive.lua index c1a38e6dd..807cf88b4 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/drive.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/drive.lua @@ -10,9 +10,9 @@ if fs.exists( sPath ) then write( fs.getDrive( sPath ) .. " (" ) local nSpace = fs.getFreeSpace( sPath ) if nSpace >= 1000 * 1000 then - print( (math.floor( nSpace / (100 * 1000) ) / 10) .. "MB remaining)" ) + print( math.floor( nSpace / (100 * 1000) ) / 10 .. "MB remaining)" ) elseif nSpace >= 1000 then - print( (math.floor( nSpace / 100 ) / 10) .. "KB remaining)" ) + print( math.floor( nSpace / 100 ) / 10 .. "KB remaining)" ) else print( nSpace .. "B remaining)" ) end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua b/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua index e481dd9cd..2d7d9357e 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua @@ -95,7 +95,7 @@ local function save( _sPath ) local function innerSave() file, fileerr = fs.open( _sPath, "w" ) if file then - for n, sLine in ipairs( tLines ) do + for _, sLine in ipairs( tLines ) do file.write( sLine .. "\n" ) end else @@ -287,7 +287,7 @@ local tMenuFuncs = { if bReadOnly then sStatus = "Access denied" else - local ok, err, fileerr = save( sPath ) + local ok, _, fileerr = save( sPath ) if ok then sStatus="Saved to "..sPath else @@ -357,7 +357,7 @@ local tMenuFuncs = { term.redirect( printerTerminal ) local ok, error = pcall( function() term.scroll() - for n, sLine in ipairs( tLines ) do + for _, sLine in ipairs( tLines ) do print( sLine ) end end ) @@ -385,7 +385,7 @@ local tMenuFuncs = { end, Run = function() local sTempPath = "/.temp" - local ok, err = save( sTempPath ) + local ok = save( sTempPath ) if ok then local nTask = shell.openTab( sTempPath ) if nTask then @@ -411,7 +411,7 @@ local function doMenuItem( _n ) end local function setCursor( newX, newY ) - local oldX, oldY = x, y + local _, oldY = x, y x, y = newX, newY local screenX = x - scrollX local screenY = y - scrollY @@ -476,7 +476,6 @@ end while bRunning do local sEvent, param, param2, param3 = os.pullEvent() if sEvent == "key" then - local oldX, oldY = x, y if param == keys.up then -- Up if not bMenu then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua index bd0bb12b4..5011458ca 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua @@ -186,8 +186,8 @@ local function drawInterface() term.write("\127\127") -- Left and Right Selected Colours - for i=18,18 do - term.setCursorPos(w-1, i) + do + term.setCursorPos(w-1, 18) if leftColour ~= nil then term.setBackgroundColour( leftColour ) term.write(" ") @@ -269,7 +269,7 @@ local function accessMenu() for k,v in pairs(mChoices) do if selection==k then term.setTextColour(colours.yellow) - local ox,_ = term.getCursorPos() + local ox = term.getCursorPos() term.write("["..string.rep(" ",#v).."]") term.setCursorPos(ox+1,h) term.setTextColour(colours.white) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua index d58bb0a4a..232f6d863 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua @@ -66,8 +66,8 @@ local function printCentred( yc, stg ) end local function centerOrgin() - XOrgin = math.floor((TermW/2)-(SizeW/2)) - YOrgin = math.floor((TermH/2)-(SizeH/2)) + XOrgin = math.floor(TermW/2-SizeW/2) + YOrgin = math.floor(TermH/2-SizeH/2) end local function reMap() @@ -177,7 +177,6 @@ local function loadLevel(nNum) local sLevelD = sDir .. "/levels/" .. tostring(nNum)..".dat" if not ( fs.exists(sLevelD) or fs.isDir(sLevelD) ) then return error("Level Not Exists : "..sLevelD) end fLevel = fs.open(sLevelD,"r") - local Line = 0 local wl = true Blocks = tonumber(string.sub(fLevel.readLine(),1,1)) local xSize = string.len(fLevel.readLine())+2 @@ -557,7 +556,7 @@ function InterFace.render() elseif p3 == TermH and p2 >= TermW-4 and p2 <= TermW-3 then bPaused = not bPaused fSpeedS = false - Speed = (bPaused and 0) or nSpeed + Speed = bPaused and 0 or nSpeed if Speed > 0 then Tick = os.startTimer(Speed) else @@ -567,7 +566,7 @@ function InterFace.render() elseif p3 == TermH and p2 >= TermW-1 then bPaused = false fSpeedS = not fSpeedS - Speed = (fSpeedS and fSpeed) or nSpeed + Speed = fSpeedS and fSpeed or nSpeed Tick = os.startTimer(Speed) InterFace.drawBar() elseif p3-1 < YOrgin+SizeH+1 and p3-1 > YOrgin and @@ -596,7 +595,6 @@ local function startG(LevelN) drawStars() loadLevel(LevelN) centerOrgin() - local create = true drawMap() InterFace.drawBar() gRender("start") diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/adventure.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/adventure.lua index 61f373e8e..eef035301 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/adventure.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/adventure.lua @@ -342,7 +342,7 @@ local function getTimeOfDay() end local function isSunny() - return (getTimeOfDay() < 10) + return getTimeOfDay() < 10 end local function getRoom( x, y, z, dontCreate ) @@ -365,7 +365,7 @@ local function getRoom( x, y, z, dontCreate ) -- Add animals if math.random(1,3) == 1 then - for n = 1,math.random(1,2) do + for _ = 1,math.random(1,2) do local sAnimal = tAnimals[ math.random( 1, #tAnimals ) ] room.items[ sAnimal ] = items[ sAnimal ] end @@ -478,7 +478,7 @@ local function findItem( _tList, _sQuery ) return sItem end if tItem.aliases ~= nil then - for n, sAlias in pairs( tItem.aliases ) do + for _, sAlias in pairs( tItem.aliases ) do if sAlias == _sQuery then return sItem end @@ -613,7 +613,7 @@ local function doCommand( text ) end for sCommand, t in pairs( tMatches ) do - for n, sMatch in pairs( t ) do + for _, sMatch in pairs( t ) do local tCaptures = { string.match( text, "^" .. sMatch .. "$" ) } if #tCaptures ~= 0 then local fnCommand = commands[ sCommand ] @@ -679,7 +679,7 @@ function commands.look( _sTarget ) end if tItem then - print( tItem.desc or ("You see nothing special about "..sItem..".") ) + print( tItem.desc or "You see nothing special about "..sItem.."." ) else print( "You don't see any ".._sTarget.." here." ) end @@ -752,7 +752,7 @@ function commands.dig( _sDir, _sTool ) tTool = inventory[ sTool ] end - local bActuallyDigging = (room.exits[ _sDir ] ~= true) + local bActuallyDigging = room.exits[ _sDir ] ~= true if bActuallyDigging then if sTool == nil or tTool.toolType ~= "pick" then print( "You need to use a pickaxe to dig through stone." ) @@ -1021,7 +1021,7 @@ function commands.cbreak( _sItem, _sTool ) print( "The "..tItem.aliases[1].." dies." ) if tItem.drops then - for n, sDrop in pairs( tItem.drops ) do + for _, sDrop in pairs( tItem.drops ) do if not room.items[sDrop] then print( "The "..tItem.aliases[1].." dropped "..sDrop.."." ) room.items[sDrop] = items[sDrop] @@ -1037,7 +1037,7 @@ function commands.cbreak( _sItem, _sTool ) end if tItem.hitDrops then - for n, sDrop in pairs( tItem.hitDrops ) do + for _, sDrop in pairs( tItem.hitDrops ) do if not room.items[sDrop] then print( "The "..tItem.aliases[1].." dropped "..sDrop.."." ) room.items[sDrop] = items[sDrop] @@ -1071,18 +1071,17 @@ function commands.craft( _sItem ) return end - local room = getRoom( x,y,z ) local sItem = findItem( items, _sItem ) - local tRecipe = (sItem and tRecipes[ sItem ]) or nil + local tRecipe = sItem and tRecipes[ sItem ] or nil if tRecipe then - for n,sReq in ipairs( tRecipe ) do + for _,sReq in ipairs( tRecipe ) do if inventory[sReq] == nil then print( "You don't have the items you need to craft "..sItem.."." ) return end end - for n,sReq in ipairs( tRecipe ) do + for _,sReq in ipairs( tRecipe ) do inventory[sReq] = nil end inventory[ sItem ] = items[ sItem ] @@ -1223,7 +1222,7 @@ local function simulate() -- Spawn monsters if room.nMonsters < 2 and - ((h == 0 and not isSunny() and not room.items["a torch"]) or room.dark) and + (h == 0 and not isSunny() and not room.items["a torch"] or room.dark) and math.random(1,6) == 1 then local sMonster = tMonsters[ math.random(1,#tMonsters) ] @@ -1240,7 +1239,7 @@ local function simulate() -- Burn monsters if h == 0 and isSunny() then - for n,sMonster in ipairs( tMonsters ) do + for _,sMonster in ipairs( tMonsters ) do if room.items[sMonster] and items[sMonster].nocturnal then room.items[sMonster] = nil if sx == 0 and sy == 0 and sz == 0 and not room.dark then @@ -1258,10 +1257,10 @@ local function simulate() -- Make monsters attack local room = getRoom( x, y, z ) if nTimeInRoom >= 2 and not bNewMonstersThisRoom then - for n,sMonster in ipairs( tMonsters ) do + for _,sMonster in ipairs( tMonsters ) do if room.items[sMonster] then if math.random(1,4) == 1 and - not (y == 0 and isSunny() and (sMonster == "a spider")) then + not (y == 0 and isSunny() and sMonster == "a spider") then if sMonster == "a creeper" then if room.dark then print( "A creeper explodes." ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/dj.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/dj.lua index 4cc98a3ef..81775248b 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/dj.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/dj.lua @@ -23,7 +23,7 @@ elseif sCommand == "play" or sCommand == nil then if sName == nil then -- No disc specified, pick one at random local tNames = {} - for n,sName in ipairs( peripheral.getNames() ) do + for _,sName in ipairs( peripheral.getNames() ) do if disk.isPresent( sName ) and disk.hasAudio( sName ) then table.insert( tNames, sName ) end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua index 33c7eed8f..58eb72fc0 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua @@ -2,15 +2,13 @@ -- Display the start screen local w,h = term.getSize() -local titleColour, headingColour, textColour, wormColour, fruitColour +local headingColour, textColour, wormColour, fruitColour if term.isColour() then - titleColour = colours.red headingColour = colours.yellow textColour = colours.white wormColour = colours.green fruitColour = colours.red else - titleColour = colours.white headingColour = colours.white textColour = colours.white wormColour = colours.white @@ -27,8 +25,6 @@ end local xVel,yVel = 1,0 local xPos, yPos = math.floor(w/2), math.floor(h/2) local pxVel, pyVel = nil, nil - -local nLength = 1 local nExtraLength = 6 local bRunning = true @@ -103,7 +99,6 @@ local function drawMenu() end local function update( ) - local x,y = xPos,yPos if pxVel and pyVel then xVel, yVel = pxVel, pyVel pxVel, pyVel = nil, nil @@ -190,7 +185,7 @@ end drawMenu() drawFrontend() while true do - local e,key = os.pullEvent( "key" ) + local _,key = os.pullEvent( "key" ) if key == keys.up or key == keys.w then -- Up if nDifficulty > 1 then @@ -228,7 +223,7 @@ addFruit() -- Play the game local timer = os.startTimer(0) while bRunning do - local event, p1, p2 = os.pullEvent() + local event, p1 = os.pullEvent() if event == "timer" and p1 == timer then timer = os.startTimer(nInterval) update( false ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/gps.lua b/src/main/resources/assets/computercraft/lua/rom/programs/gps.lua index fc1ae7614..77621de75 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/gps.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/gps.lua @@ -28,7 +28,7 @@ elseif sCommand == "host" then -- Find a modem local sModemSide = nil - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then sModemSide = sSide break @@ -80,7 +80,7 @@ elseif sCommand == "host" then -- Print the number of requests handled nServed = nServed + 1 if nServed > 1 then - local x,y = term.getCursorPos() + local _,y = term.getCursorPos() term.setCursorPos(1,y-1) end print( nServed.." GPS requests served" ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/help.lua b/src/main/resources/assets/computercraft/lua/rom/programs/help.lua index 2925cf72d..c8653616a 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/help.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/help.lua @@ -14,7 +14,7 @@ if sTopic == "index" then end local sFile = help.lookup( sTopic ) -local file = ((sFile ~= nil) and io.open( sFile )) or nil +local file = sFile ~= nil and io.open( sFile ) or nil if file then local sContents = file:read("*a") file:close() diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/list.lua b/src/main/resources/assets/computercraft/lua/rom/programs/list.lua index 14ed40439..f493d8ae5 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/list.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/list.lua @@ -18,7 +18,7 @@ local tFiles = {} local tDirs = {} local bShowHidden = settings.get( "list.show_hidden" ) -for n, sItem in pairs( tAll ) do +for _, sItem in pairs( tAll ) do if bShowHidden or string.sub( sItem, 1, 1 ) ~= "." then local sPath = fs.combine( sDir, sItem ) if fs.isDir( sPath ) then 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 e1a4cb0f2..50766b973 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua @@ -67,7 +67,7 @@ while bRunning do local nForcePrint = 0 local func, e = load( s, "=lua", "t", tEnv ) - local func2, e2 = load( "return _echo("..s..");", "=lua", "t", tEnv ) + local func2 = load( "return _echo("..s..");", "=lua", "t", tEnv ) if not func then if func2 then func = func2 @@ -84,7 +84,7 @@ while bRunning do local tResults = table.pack( pcall( func ) ) if tResults[1] then local n = 1 - while n < tResults.n or (n <= nForcePrint) do + while n < tResults.n or n <= nForcePrint do local value = tResults[ n + 1 ] if type( value ) == "table" then local metatable = getmetatable( value ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/move.lua b/src/main/resources/assets/computercraft/lua/rom/programs/move.lua index a794c90b9..5f12588e7 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/move.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/move.lua @@ -9,7 +9,7 @@ local sSource = shell.resolve( tArgs[1] ) local sDest = shell.resolve( tArgs[2] ) local tFiles = fs.find( sSource ) if #tFiles > 0 then - for n,sFile in ipairs( tFiles ) do + for _,sFile in ipairs( tFiles ) do if fs.isDir( sDest ) then fs.move( sFile, fs.combine( sDest, fs.getName(sFile) ) ) elseif #tFiles == 1 then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/pocket/falling.lua b/src/main/resources/assets/computercraft/lua/rom/programs/pocket/falling.lua index 3680b6b66..afecfa67b 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/pocket/falling.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/pocket/falling.lua @@ -424,7 +424,7 @@ local function playGame() end if #rows>0 then - for i=1,4 do + for _=1,4 do sleep(.1) for r=1,#rows do r=rows[r] @@ -469,7 +469,6 @@ local function playGame() end local function blockFall() - local result = false if testBlockAt(curBlock,curX,curY+1,curRot) then pitBlock(curBlock,curX,curY,curRot) --detect rows that clear @@ -524,16 +523,16 @@ local function playGame() dropTimer=os.startTimer(dropSpeed) end if dx+dr~=0 then - if not testBlockAt(curBlock,curX+dx,curY+dy,(dr>0 and curRot%#curBlock+dr or curRot)) then + if not testBlockAt(curBlock,curX+dx,curY+dy,dr>0 and curRot%#curBlock+dr or curRot) then eraseBlockAt(curBlock,curX,curY,curRot) curX=curX+dx curY=curY+dy - curRot=dr==0 and curRot or (curRot%#curBlock+dr) + curRot=dr==0 and curRot or curRot%#curBlock+dr drawBlockAt(curBlock,curX,curY,curRot) end end elseif e[1]=="term_resize" then - local w,h=term.getSize() + local _,h=term.getSize() if h==20 then heightAdjust=0 else @@ -617,7 +616,7 @@ local function runMenu() level=math.max(level-1,1) drawMenu() elseif key>=keys.one and key<=keys.nine and selected==1 then - level=(key-keys.one) + 1 + level=key-keys.one + 1 drawMenu() elseif key==keys.up or key==keys.w then selected=selected-1 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 329f15db8..2bf5404ee 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 @@ -9,7 +9,7 @@ end local sOpenedModem = nil local function openModem() - for n,sModem in ipairs( peripheral.getNames() ) do + for _,sModem in ipairs( peripheral.getNames() ) do if peripheral.getType( sModem ) == "modem" then if not rednet.isOpen( sModem ) then rednet.open( sModem ) @@ -94,7 +94,7 @@ if sCommand == "host" then end local function printUsers() - local x,y = term.getCursorPos() + local _,y = term.getCursorPos() term.setCursorPos( 1, y - 1 ) term.clearLine() if nUsers == 1 then @@ -108,7 +108,7 @@ if sCommand == "host" then local ok, error = pcall( function() parallel.waitForAny( function() while true do - local sEvent, timer = os.pullEvent( "timer" ) + local _, timer = os.pullEvent( "timer" ) local nUserID = tPingPongTimer[ timer ] if nUserID and tUsers[ nUserID ] then local tUser = tUsers[ nUserID ] @@ -148,7 +148,7 @@ if sCommand == "host" then ["users"] = function( tUser, sContent ) send( "* Connected Users:", tUser.nUserID ) local sUsers = "*" - for nUserID, tUser in pairs( tUsers ) do + for _, tUser in pairs( tUsers ) do sUsers = sUsers .. " " .. tUser.sUsername end send( sUsers, tUser.nUserID ) @@ -156,7 +156,7 @@ if sCommand == "host" then ["help"] = function( tUser, sContent ) send( "* Available commands:", tUser.nUserID ) local sCommands = "*" - for sCommand, fnCommand in pairs( tCommands ) do + for sCommand in pairs( tCommands ) do sCommands = sCommands .. " /" .. sCommand end send( sCommands.." /logout", tUser.nUserID ) @@ -297,8 +297,7 @@ elseif sCommand == "join" then promptWindow.restoreCursor() local function drawTitle() - local x,y = titleWindow.getCursorPos() - local w,h = titleWindow.getSize() + local w = titleWindow.getSize() local sTitle = sUsername.." on "..sHostname titleWindow.setTextColour( highlightColour ) titleWindow.setCursorPos( math.floor( w/2 - string.len(sTitle)/2 ), 1 ) @@ -410,7 +409,7 @@ elseif sCommand == "join" then term.redirect( parentTerm ) -- Print error notice - local w,h = term.getSize() + local _,h = term.getSize() term.setCursorPos( 1, h ) term.clearLine() term.setCursorBlink( false ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/repeat.lua b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/repeat.lua index c8fdc89b8..452ffb587 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/repeat.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/repeat.lua @@ -1,7 +1,7 @@ -- Find modems local tModems = {} -for n,sModem in ipairs( peripheral.getNames() ) do +for _,sModem in ipairs( peripheral.getNames() ) do if peripheral.getType( sModem ) == "modem" then table.insert( tModems, sModem ) end @@ -59,7 +59,7 @@ local ok, error = pcall( function() -- Log the event nTransmittedMessages = nTransmittedMessages + 1 - local x,y = term.getCursorPos() + local _,y = term.getCursorPos() term.setCursorPos( 1, y - 1 ) term.clearLine() if nTransmittedMessages == 1 then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/redstone.lua b/src/main/resources/assets/computercraft/lua/rom/programs/redstone.lua index 8a6d2db86..ff38a89ef 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/redstone.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/redstone.lua @@ -17,7 +17,7 @@ if sCommand == "probe" then local count = 0 local bundledCount = 0 - for n,sSide in ipairs( redstone.getSides() ) do + for _,sSide in ipairs( redstone.getSides() ) do if redstone.getBundledInput( sSide ) > 0 then bundledCount = bundledCount + 1 end @@ -39,7 +39,7 @@ if sCommand == "probe" then if bundledCount > 0 then print() print( "Bundled inputs:" ) - for i,sSide in ipairs( redstone.getSides() ) do + for _,sSide in ipairs( redstone.getSides() ) do local nInput = redstone.getBundledInput( sSide ) if nInput ~= 0 then write( sSide..": " ) @@ -69,7 +69,7 @@ elseif sCommand == "pulse" then local sSide = tArgs[2] local nCount = tonumber( tArgs[3] ) or 1 local nPeriod = tonumber( tArgs[4] ) or 0.5 - for n=1,nCount do + for _=1,nCount do redstone.setOutput( sSide, true ) sleep( nPeriod / 2 ) redstone.setOutput( sSide, false ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/set.lua b/src/main/resources/assets/computercraft/lua/rom/programs/set.lua index 9acad56c2..94ef6b621 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/set.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/set.lua @@ -2,7 +2,7 @@ local tArgs = { ... } if #tArgs == 0 then -- "set" - local x,y = term.getCursorPos() + local _,y = term.getCursorPos() local tSettings = {} for n,sName in ipairs( settings.getNames() ) do tSettings[n] = textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua b/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua index 3c15e04b3..13c4b90c0 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua @@ -9,10 +9,10 @@ if multishell then end local bExit = false -local sDir = (parentShell and parentShell.dir()) or "" -local sPath = (parentShell and parentShell.path()) or ".:/rom/programs" -local tAliases = (parentShell and parentShell.aliases()) or {} -local tCompletionInfo = (parentShell and parentShell.getCompletionInfo()) or {} +local sDir = parentShell and parentShell.dir() or "" +local sPath = parentShell and parentShell.path() or ".:/rom/programs" +local tAliases = parentShell and parentShell.aliases() or {} +local tCompletionInfo = parentShell and parentShell.getCompletionInfo() or {} local tProgramStack = {} local shell = {} @@ -287,7 +287,7 @@ function shell.programs( _bIncludeHidden ) -- Sort and return local tItemList = {} - for sItem, b in pairs( tItems ) do + for sItem in pairs( tItems ) do table.insert( tItemList, sItem ) end table.sort( tItemList ) @@ -304,7 +304,7 @@ local function completeProgram( sLine ) local tSeen = {} -- Add aliases - for sAlias, sCommand in pairs( tAliases ) do + for sAlias in pairs( tAliases ) do if #sAlias > #sLine and string.sub( sAlias, 1, #sLine ) == sLine then local sResult = string.sub( sAlias, #sLine + 1 ) if not tSeen[ sResult ] then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/dance.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/dance.lua index 6f32a1df0..246992f78 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/dance.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/dance.lua @@ -81,7 +81,7 @@ textutils.slowWrite( "Preparing to get down." ) textutils.slowPrint( "..", 0.75 ) local sAudio = nil -for n,sName in pairs( peripheral.getNames() ) do +for _,sName in pairs( peripheral.getNames() ) do if disk.hasAudio( sName ) then disk.playAudio( sName ) print( "Jamming to "..disk.getAudioTitle( sName ) ) @@ -95,7 +95,7 @@ print( "Press any key to stop the groove" ) parallel.waitForAny( function() while not bEnd do - local event, key = os.pullEvent("key") + local _, key = os.pullEvent("key") if key ~= keys.escape then return end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/excavate.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/excavate.lua index 677e43678..5e7f32274 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/excavate.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/excavate.lua @@ -81,7 +81,7 @@ local function collect() if nTotalItems > collected then collected = nTotalItems if math.fmod(collected + unloaded, 50) == 0 then - print( "Mined "..(collected + unloaded).." items." ) + print( "Mined "..collected + unloaded.." items." ) end end @@ -98,9 +98,8 @@ function refuel( ammount ) return true end - local needed = ammount or (xPos + zPos + depth + 2) + local needed = ammount or xPos + zPos + depth + 2 if turtle.getFuelLevel() < needed then - local fueled = false for n=1,16 do if turtle.getItemCount(n) > 0 then turtle.select(n) @@ -292,7 +291,7 @@ local alternate = 0 local done = false while not done do for n=1,size do - for m=1,size-1 do + for _=1,size-1 do if not tryForwards() then done = true break @@ -354,4 +353,4 @@ if reseal then turtle.placeDown() end -print( "Mined "..(collected + unloaded).." items total." ) +print( "Mined "..collected + unloaded.." items total." ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/refuel.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/refuel.lua index d9f606f8c..fa69de01c 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/refuel.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/refuel.lua @@ -23,7 +23,7 @@ end if turtle.getFuelLevel() ~= "unlimited" then for n = 1, 16 do -- Stop if we've reached the limit, or are fully refuelled. - if (nLimit and nLimit <= 0) or turtle.getFuelLevel() >= turtle.getFuelLimit() then + if nLimit and nLimit <= 0 or turtle.getFuelLevel() >= turtle.getFuelLimit() then break end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/tunnel.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/tunnel.lua index 9345a6225..9bf4e2665 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/tunnel.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/tunnel.lua @@ -15,8 +15,6 @@ if length < 1 then print( "Tunnel length must be positive" ) return end - -local depth = 0 local collected = 0 local function collect() diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/turn.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/turn.lua index 4ab6151ec..df90142d2 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/turn.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/turn.lua @@ -31,7 +31,7 @@ while nArg <= #tArgs do local fnHandler = tHandlers[string.lower(sDirection)] if fnHandler then - for n=1,nDistance do + for _=1,nDistance do fnHandler( nArg ) end else diff --git a/src/main/resources/assets/computercraft/lua/rom/startup.lua b/src/main/resources/assets/computercraft/lua/rom/startup.lua index e6b396b39..af8ff4fbc 100644 --- a/src/main/resources/assets/computercraft/lua/rom/startup.lua +++ b/src/main/resources/assets/computercraft/lua/rom/startup.lua @@ -163,7 +163,7 @@ if settings.get( "shell.allow_startup" ) then tUserStartups = findStartups( "/" ) end if settings.get( "shell.allow_disk_startup" ) then - for n,sName in pairs( peripheral.getNames() ) do + for _,sName in pairs( peripheral.getNames() ) do if disk.isPresent( sName ) and disk.hasData( sName ) then local startups = findStartups( disk.getMountPath( sName ) ) if startups then