mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 05:33:00 +00:00 
			
		
		
		
	Replace string.len with #
This commit is contained in:
		
							
								
								
									
										35
									
								
								.luacheckrc
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								.luacheckrc
									
									
									
									
									
								
							| @@ -1,35 +0,0 @@ | |||||||
| std = "max" |  | ||||||
|  |  | ||||||
| ignore = { |  | ||||||
|     -- Allow access to undefined globals or their fields. In the future we'll |  | ||||||
|     -- define all of CC's globals within this file |  | ||||||
|     '113', '143', |  | ||||||
|  |  | ||||||
|     -- FIXME: Ignore unused arguments and loop variables |  | ||||||
|     '212', '213', |  | ||||||
|  |  | ||||||
|     -- Disable line is too long for now. It would be possible to clean |  | ||||||
|     -- this up in the future. |  | ||||||
|     '631', |  | ||||||
| } |  | ||||||
|  |  | ||||||
| -- Only run the linter on ROM and bios for now, as the treasure disks |  | ||||||
| -- are largely unsupported. |  | ||||||
| include_files = { |  | ||||||
|     'src/main/resources/assets/computercraft/lua/rom', |  | ||||||
|     'src/main/resources/assets/computercraft/lua/bios.lua', |  | ||||||
|     'src/test/resources/test-rom', |  | ||||||
| } |  | ||||||
|  |  | ||||||
| files['src/main/resources/assets/computercraft/lua/bios.lua'] = { |  | ||||||
|     -- Allow declaring and mutating globals |  | ||||||
|     allow_defined_top = true, |  | ||||||
|     ignore = { '112', '121', '122', '131', '142' }, |  | ||||||
| } |  | ||||||
|  |  | ||||||
| files['src/main/resources/assets/computercraft/lua/rom/apis'] = { |  | ||||||
|     -- APIs may define globals on the top level. We'll ignore unused globals, |  | ||||||
|     -- as obviously they may be used outside that API. |  | ||||||
|     allow_defined_top = true, |  | ||||||
|     ignore = { '131' }, |  | ||||||
| } |  | ||||||
| @@ -7,20 +7,22 @@ | |||||||
|  |  | ||||||
| (at / | (at / | ||||||
|   (linters |   (linters | ||||||
|     ;; It'd be nice to avoid this, but right now there's a lot of instances of it. |     ;; It'd be nice to avoid this, but right now there's a lot of instances of | ||||||
|  |     ;; it. | ||||||
|     -var:set-loop |     -var:set-loop | ||||||
|  |  | ||||||
|     ;; It's useful to name arguments for documentation, so we allow this. It'd |     ;; 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. |     ;; be good to find a compromise in the future, but this works for now. | ||||||
|     -var:unused-arg)) |     -var:unused-arg)) | ||||||
|  |  | ||||||
| ;; We disable the two global linters in bios.lua and the APIs. In the future | ;; We disable the unused global linter in bios.lua and the APIs. In the future | ||||||
| ;; hopefully we'll get illuaminate to handle this. | ;; hopefully we'll get illuaminate to handle this. | ||||||
| (at | (at | ||||||
|   (/src/main/resources/assets/computercraft/lua/bios.lua |   (/src/main/resources/assets/computercraft/lua/bios.lua | ||||||
|    /src/main/resources/assets/computercraft/lua/rom/apis/) |    /src/main/resources/assets/computercraft/lua/rom/apis/) | ||||||
|   (linters -var:set-global -var:unused-global)) |   (linters -var:unused-global) | ||||||
|  |   (lint | ||||||
|  |     (allow-toplevel-global true))) | ||||||
|  |  | ||||||
| ;; These warnings are broken right now | ;; These warnings are broken right now | ||||||
| (at completion.lua (linters -doc:malformed-type)) |  | ||||||
| (at (bios.lua worm.lua) (linters -control:unreachable)) | (at (bios.lua worm.lua) (linters -control:unreachable)) | ||||||
|   | |||||||
| @@ -207,13 +207,13 @@ function write( sText ) | |||||||
|     end |     end | ||||||
|  |  | ||||||
|     -- Print the line with proper word wrapping |     -- Print the line with proper word wrapping | ||||||
|     while string.len(sText) > 0 do |     while #sText > 0 do | ||||||
|         local whitespace = string.match( sText, "^[ \t]+" ) |         local whitespace = string.match( sText, "^[ \t]+" ) | ||||||
|         if whitespace then |         if whitespace then | ||||||
|             -- Print whitespace |             -- Print whitespace | ||||||
|             term.write( whitespace ) |             term.write( whitespace ) | ||||||
|             x, y = term.getCursorPos() |             x, y = term.getCursorPos() | ||||||
|             sText = string.sub( sText, string.len(whitespace) + 1 ) |             sText = string.sub( sText, #whitespace + 1 ) | ||||||
|         end |         end | ||||||
|  |  | ||||||
|         local newline = string.match( sText, "^\n" ) |         local newline = string.match( sText, "^\n" ) | ||||||
| @@ -225,10 +225,10 @@ function write( sText ) | |||||||
|  |  | ||||||
|         local text = string.match( sText, "^[^ \t\n]+" ) |         local text = string.match( sText, "^[^ \t\n]+" ) | ||||||
|         if text then |         if text then | ||||||
|             sText = string.sub( sText, string.len(text) + 1 ) |             sText = string.sub( sText, #text + 1 ) | ||||||
|             if string.len(text) > w then |             if #text > w then | ||||||
|                 -- Print a multiline word |                 -- Print a multiline word | ||||||
|                 while string.len( text ) > 0 do |                 while #text > 0 do | ||||||
|                     if x > w then |                     if x > w then | ||||||
|                         newLine() |                         newLine() | ||||||
|                     end |                     end | ||||||
| @@ -238,7 +238,7 @@ function write( sText ) | |||||||
|                 end |                 end | ||||||
|             else |             else | ||||||
|                 -- Print a word normally |                 -- Print a word normally | ||||||
|                 if x + string.len(text) - 1 > w then |                 if x + #text - 1 > w then | ||||||
|                     newLine() |                     newLine() | ||||||
|                 end |                 end | ||||||
|                 term.write( text ) |                 term.write( text ) | ||||||
| @@ -299,7 +299,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault ) | |||||||
|     local tCompletions |     local tCompletions | ||||||
|     local nCompletion |     local nCompletion | ||||||
|     local function recomplete() |     local function recomplete() | ||||||
|         if _fnComplete and nPos == string.len(sLine) then |         if _fnComplete and nPos == #sLine then | ||||||
|             tCompletions = _fnComplete( sLine ) |             tCompletions = _fnComplete( sLine ) | ||||||
|             if tCompletions and #tCompletions > 0 then |             if tCompletions and #tCompletions > 0 then | ||||||
|                 nCompletion = 1 |                 nCompletion = 1 | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ function slowWrite( sText, nRate ) | |||||||
|  |  | ||||||
|     sText = tostring( sText ) |     sText = tostring( sText ) | ||||||
|     local x, y = term.getCursorPos() |     local x, y = term.getCursorPos() | ||||||
|     local len = string.len( sText ) |     local len = #sText | ||||||
|  |  | ||||||
|     for n = 1, len do |     for n = 1, len do | ||||||
|         term.setCursorPos( x, y ) |         term.setCursorPos( x, y ) | ||||||
| @@ -116,7 +116,7 @@ local function tabulateCommon( bPaged, ... ) | |||||||
|                 if type( sItem ) ~= "string" then |                 if type( sItem ) ~= "string" then | ||||||
|                     error( "bad argument #" .. n .. "." .. nu .. " (expected string, got " .. type( sItem ) .. ")", 3 ) |                     error( "bad argument #" .. n .. "." .. nu .. " (expected string, got " .. type( sItem ) .. ")", 3 ) | ||||||
|                 end |                 end | ||||||
|                 nMaxLen = math.max( string.len( sItem ) + 1, nMaxLen ) |                 nMaxLen = math.max( #sItem + 1, nMaxLen ) | ||||||
|             end |             end | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| @@ -388,7 +388,7 @@ function complete( sSearchText, tSearchTable ) | |||||||
|     end |     end | ||||||
|  |  | ||||||
|     local sPart = string.sub( sSearchText, nStart ) |     local sPart = string.sub( sSearchText, nStart ) | ||||||
|     local nPartLength = string.len( sPart ) |     local nPartLength = #sPart | ||||||
|  |  | ||||||
|     local tResults = {} |     local tResults = {} | ||||||
|     local tSeen = {} |     local tSeen = {} | ||||||
|   | |||||||
| @@ -287,7 +287,7 @@ while #tProcesses > 0 do | |||||||
|                     tabStart = 2 |                     tabStart = 2 | ||||||
|                 end |                 end | ||||||
|                 for n = nScrollPos, #tProcesses do |                 for n = nScrollPos, #tProcesses do | ||||||
|                     local tabEnd = tabStart + string.len( tProcesses[n].sTitle ) + 1 |                     local tabEnd = tabStart + #tProcesses[n].sTitle + 1 | ||||||
|                     if x >= tabStart and x <= tabEnd then |                     if x >= tabStart and x <= tabEnd then | ||||||
|                         selectProcess( n ) |                         selectProcess( n ) | ||||||
|                         redrawMenu() |                         redrawMenu() | ||||||
|   | |||||||
| @@ -62,7 +62,7 @@ end | |||||||
| table.insert( tMenuItems, "Exit" ) | table.insert( tMenuItems, "Exit" ) | ||||||
|  |  | ||||||
| local sStatus = "Press Ctrl to access menu" | local sStatus = "Press Ctrl to access menu" | ||||||
| if string.len( sStatus ) > w - 5 then | if #sStatus > w - 5 then | ||||||
|     sStatus = "Press Ctrl for menu" |     sStatus = "Press Ctrl for menu" | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -144,13 +144,13 @@ local function tryWrite( sLine, regex, colour ) | |||||||
|         end |         end | ||||||
|         term.write( match ) |         term.write( match ) | ||||||
|         term.setTextColour( textColour ) |         term.setTextColour( textColour ) | ||||||
|         return string.sub( sLine, string.len(match) + 1 ) |         return string.sub( sLine, #match + 1 ) | ||||||
|     end |     end | ||||||
|     return nil |     return nil | ||||||
| end | end | ||||||
|  |  | ||||||
| local function writeHighlighted( sLine ) | local function writeHighlighted( sLine ) | ||||||
|     while string.len(sLine) > 0 do |     while #sLine > 0 do | ||||||
|         sLine = |         sLine = | ||||||
|             tryWrite( sLine, "^%-%-%[%[.-%]%]", commentColour ) or |             tryWrite( sLine, "^%-%-%[%[.-%]%]", commentColour ) or | ||||||
|             tryWrite( sLine, "^%-%-.*", commentColour ) or |             tryWrite( sLine, "^%-%-.*", commentColour ) or | ||||||
| @@ -188,7 +188,7 @@ end | |||||||
|  |  | ||||||
| local function recomplete() | local function recomplete() | ||||||
|     local sLine = tLines[y] |     local sLine = tLines[y] | ||||||
|     if not bMenu and not bReadOnly and x == string.len(sLine) + 1 then |     if not bMenu and not bReadOnly and x == #sLine + 1 then | ||||||
|         tCompletions = complete( sLine ) |         tCompletions = complete( sLine ) | ||||||
|         if tCompletions and #tCompletions > 0 then |         if tCompletions and #tCompletions > 0 then | ||||||
|             nCompletion = 1 |             nCompletion = 1 | ||||||
| @@ -248,7 +248,7 @@ local function redrawMenu() | |||||||
|     term.clearLine() |     term.clearLine() | ||||||
|  |  | ||||||
|     -- Draw line numbers |     -- Draw line numbers | ||||||
|     term.setCursorPos( w - string.len( "Ln " .. y ) + 1, h ) |     term.setCursorPos( w - #( "Ln " .. y ) + 1, h ) | ||||||
|     term.setTextColour( highlightColour ) |     term.setTextColour( highlightColour ) | ||||||
|     term.write( "Ln " ) |     term.write( "Ln " ) | ||||||
|     term.setTextColour( textColour ) |     term.setTextColour( textColour ) | ||||||
| @@ -468,7 +468,7 @@ local function acceptCompletion() | |||||||
|         -- Append the completion |         -- Append the completion | ||||||
|         local sCompletion = tCompletions[ nCompletion ] |         local sCompletion = tCompletions[ nCompletion ] | ||||||
|         tLines[y] = tLines[y] .. sCompletion |         tLines[y] = tLines[y] .. sCompletion | ||||||
|         setCursor( x + string.len( sCompletion ), y ) |         setCursor( x + #sCompletion , y ) | ||||||
|     end |     end | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -490,7 +490,7 @@ while bRunning do | |||||||
|                 elseif y > 1 then |                 elseif y > 1 then | ||||||
|                     -- Move cursor up |                     -- Move cursor up | ||||||
|                     setCursor( |                     setCursor( | ||||||
|                         math.min( x, string.len( tLines[y - 1] ) + 1 ), |                         math.min( x, #tLines[y - 1] + 1 ), | ||||||
|                         y - 1 |                         y - 1 | ||||||
|                     ) |                     ) | ||||||
|                 end |                 end | ||||||
| @@ -511,7 +511,7 @@ while bRunning do | |||||||
|                 elseif y < #tLines then |                 elseif y < #tLines then | ||||||
|                     -- Move cursor down |                     -- Move cursor down | ||||||
|                     setCursor( |                     setCursor( | ||||||
|                         math.min( x, string.len( tLines[y + 1] ) + 1 ), |                         math.min( x, #tLines[y + 1] + 1 ), | ||||||
|                         y + 1 |                         y + 1 | ||||||
|                     ) |                     ) | ||||||
|                 end |                 end | ||||||
| @@ -520,7 +520,7 @@ while bRunning do | |||||||
|         elseif param == keys.tab then |         elseif param == keys.tab then | ||||||
|             -- Tab |             -- Tab | ||||||
|             if not bMenu and not bReadOnly then |             if not bMenu and not bReadOnly then | ||||||
|                 if nCompletion and x == string.len(tLines[y]) + 1 then |                 if nCompletion and x == #tLines[y] + 1 then | ||||||
|                     -- Accept autocomplete |                     -- Accept autocomplete | ||||||
|                     acceptCompletion() |                     acceptCompletion() | ||||||
|                 else |                 else | ||||||
| @@ -542,7 +542,7 @@ while bRunning do | |||||||
|                     newY = 1 |                     newY = 1 | ||||||
|                 end |                 end | ||||||
|                 setCursor( |                 setCursor( | ||||||
|                     math.min( x, string.len( tLines[newY] ) + 1 ), |                     math.min( x, #tLines[newY] + 1 ), | ||||||
|                     newY |                     newY | ||||||
|                 ) |                 ) | ||||||
|             end |             end | ||||||
| @@ -557,7 +557,7 @@ while bRunning do | |||||||
|                 else |                 else | ||||||
|                     newY = #tLines |                     newY = #tLines | ||||||
|                 end |                 end | ||||||
|                 local newX = math.min( x, string.len( tLines[newY] ) + 1 ) |                 local newX = math.min( x, #tLines[newY] + 1 ) | ||||||
|                 setCursor( newX, newY ) |                 setCursor( newX, newY ) | ||||||
|             end |             end | ||||||
|  |  | ||||||
| @@ -574,7 +574,7 @@ while bRunning do | |||||||
|             -- End |             -- End | ||||||
|             if not bMenu then |             if not bMenu then | ||||||
|                 -- Move cursor to the end |                 -- Move cursor to the end | ||||||
|                 local nLimit = string.len( tLines[y] ) + 1 |                 local nLimit = #tLines[y] + 1 | ||||||
|                 if x < nLimit then |                 if x < nLimit then | ||||||
|                     setCursor( nLimit, y ) |                     setCursor( nLimit, y ) | ||||||
|                 end |                 end | ||||||
| @@ -587,7 +587,7 @@ while bRunning do | |||||||
|                     -- Move cursor left |                     -- Move cursor left | ||||||
|                     setCursor( x - 1, y ) |                     setCursor( x - 1, y ) | ||||||
|                 elseif x == 1 and y > 1 then |                 elseif x == 1 and y > 1 then | ||||||
|                     setCursor( string.len( tLines[y - 1] ) + 1, y - 1 ) |                     setCursor( #tLines[y - 1] + 1, y - 1 ) | ||||||
|                 end |                 end | ||||||
|             else |             else | ||||||
|                 -- Move menu left |                 -- Move menu left | ||||||
| @@ -601,11 +601,11 @@ while bRunning do | |||||||
|         elseif param == keys.right then |         elseif param == keys.right then | ||||||
|             -- Right |             -- Right | ||||||
|             if not bMenu then |             if not bMenu then | ||||||
|                 local nLimit = string.len( tLines[y] ) + 1 |                 local nLimit = #tLines[y] + 1 | ||||||
|                 if x < nLimit then |                 if x < nLimit then | ||||||
|                     -- Move cursor right |                     -- Move cursor right | ||||||
|                     setCursor( x + 1, y ) |                     setCursor( x + 1, y ) | ||||||
|                 elseif nCompletion and x == string.len(tLines[y]) + 1 then |                 elseif nCompletion and x == #tLines[y] + 1 then | ||||||
|                     -- Accept autocomplete |                     -- Accept autocomplete | ||||||
|                     acceptCompletion() |                     acceptCompletion() | ||||||
|                 elseif x == nLimit and y < #tLines then |                 elseif x == nLimit and y < #tLines then | ||||||
| @@ -624,7 +624,7 @@ while bRunning do | |||||||
|         elseif param == keys.delete then |         elseif param == keys.delete then | ||||||
|             -- Delete |             -- Delete | ||||||
|             if not bMenu and not bReadOnly then |             if not bMenu and not bReadOnly then | ||||||
|                 local nLimit = string.len( tLines[y] ) + 1 |                 local nLimit = #tLines[y] + 1 | ||||||
|                 if x < nLimit then |                 if x < nLimit then | ||||||
|                     local sLine = tLines[y] |                     local sLine = tLines[y] | ||||||
|                     tLines[y] = string.sub(sLine, 1, x - 1) .. string.sub(sLine, x + 1) |                     tLines[y] = string.sub(sLine, 1, x - 1) .. string.sub(sLine, x + 1) | ||||||
| @@ -653,7 +653,7 @@ while bRunning do | |||||||
|                     end |                     end | ||||||
|                 elseif y > 1 then |                 elseif y > 1 then | ||||||
|                     -- Remove newline |                     -- Remove newline | ||||||
|                     local sPrevLen = string.len( tLines[y - 1] ) |                     local sPrevLen = #tLines[y - 1] | ||||||
|                     tLines[y - 1] = tLines[y - 1] .. tLines[y] |                     tLines[y - 1] = tLines[y - 1] .. tLines[y] | ||||||
|                     table.remove( tLines, y ) |                     table.remove( tLines, y ) | ||||||
|                     setCursor( sPrevLen + 1, y - 1 ) |                     setCursor( sPrevLen + 1, y - 1 ) | ||||||
| @@ -721,7 +721,7 @@ while bRunning do | |||||||
|             -- Input text |             -- Input text | ||||||
|             local sLine = tLines[y] |             local sLine = tLines[y] | ||||||
|             tLines[y] = string.sub(sLine, 1, x - 1) .. param .. string.sub(sLine, x) |             tLines[y] = string.sub(sLine, 1, x - 1) .. param .. string.sub(sLine, x) | ||||||
|             setCursor( x + string.len( param ), y ) |             setCursor( x + #param , y ) | ||||||
|         end |         end | ||||||
|  |  | ||||||
|     elseif sEvent == "mouse_click" then |     elseif sEvent == "mouse_click" then | ||||||
| @@ -731,7 +731,7 @@ while bRunning do | |||||||
|                 local cx, cy = param2, param3 |                 local cx, cy = param2, param3 | ||||||
|                 if cy < h then |                 if cy < h then | ||||||
|                     local newY = math.min( math.max( scrollY + cy, 1 ), #tLines ) |                     local newY = math.min( math.max( scrollY + cy, 1 ), #tLines ) | ||||||
|                     local newX = math.min( math.max( scrollX + cx, 1 ), string.len( tLines[newY] ) + 1 ) |                     local newX = math.min( math.max( scrollX + cx, 1 ), #tLines[newY] + 1 ) | ||||||
|                     setCursor( newX, newY ) |                     setCursor( newX, newY ) | ||||||
|                 end |                 end | ||||||
|             end |             end | ||||||
|   | |||||||
| @@ -148,7 +148,7 @@ local function save(path) | |||||||
|         end |         end | ||||||
|         sLine = string.sub( sLine, 1, nLastChar ) |         sLine = string.sub( sLine, 1, nLastChar ) | ||||||
|         tLines[y] = sLine |         tLines[y] = sLine | ||||||
|         if string.len( sLine ) > 0 then |         if #sLine > 0 then | ||||||
|             nLastLine = y |             nLastLine = y | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
|   | |||||||
| @@ -60,7 +60,7 @@ local tArgs = { ... } | |||||||
|  |  | ||||||
| --Functions-- | --Functions-- | ||||||
| local function printCentred( yc, stg ) | local function printCentred( yc, stg ) | ||||||
|     local xc = math.floor((TermW - string.len(stg)) / 2) + 1 |     local xc = math.floor((TermW - #stg) / 2) + 1 | ||||||
|     term.setCursorPos(xc, yc) |     term.setCursorPos(xc, yc) | ||||||
|     term.write( stg ) |     term.write( stg ) | ||||||
| end | end | ||||||
| @@ -179,7 +179,7 @@ local function loadLevel(nNum) | |||||||
|     fLevel = fs.open(sLevelD, "r") |     fLevel = fs.open(sLevelD, "r") | ||||||
|     local wl = true |     local wl = true | ||||||
|     Blocks = tonumber(string.sub(fLevel.readLine(), 1, 1)) |     Blocks = tonumber(string.sub(fLevel.readLine(), 1, 1)) | ||||||
|     local xSize = string.len(fLevel.readLine()) + 2 |     local xSize = #fLevel.readLine() + 2 | ||||||
|     local Lines = 3 |     local Lines = 3 | ||||||
|     while wl do |     while wl do | ||||||
|         local wLine = fLevel.readLine() |         local wLine = fLevel.readLine() | ||||||
| @@ -187,7 +187,7 @@ local function loadLevel(nNum) | |||||||
|             fLevel.close() |             fLevel.close() | ||||||
|             wl = false |             wl = false | ||||||
|         else |         else | ||||||
|             xSize = math.max(string.len(wLine) + 2, xSize) |             xSize = math.max(#wLine + 2, xSize) | ||||||
|             Lines = Lines + 1 |             Lines = Lines + 1 | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| @@ -197,7 +197,7 @@ local function loadLevel(nNum) | |||||||
|     fLevel.readLine() |     fLevel.readLine() | ||||||
|     for Line = 2, Lines - 1 do |     for Line = 2, Lines - 1 do | ||||||
|         local sLine = fLevel.readLine() |         local sLine = fLevel.readLine() | ||||||
|         local chars = string.len(sLine) |         local chars = #sLine | ||||||
|         for char = 1, chars do |         for char = 1, chars do | ||||||
|             local el = string.sub(sLine, char, char) |             local el = string.sub(sLine, char, char) | ||||||
|             if el == "8" then |             if el == "8" then | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ else | |||||||
| end | end | ||||||
|  |  | ||||||
| local function printCentred( y, s ) | local function printCentred( y, s ) | ||||||
|     local x = math.floor((w - string.len(s)) / 2) |     local x = math.floor((w - #s) / 2) | ||||||
|     term.setCursorPos(x, y) |     term.setCursorPos(x, y) | ||||||
|     --term.clearLine() |     --term.clearLine() | ||||||
|     term.write( s ) |     term.write( s ) | ||||||
|   | |||||||
| @@ -130,14 +130,14 @@ if sCommand == "host" then | |||||||
|                 local tCommands |                 local tCommands | ||||||
|                 tCommands = { |                 tCommands = { | ||||||
|                     ["me"] = function( tUser, sContent ) |                     ["me"] = function( tUser, sContent ) | ||||||
|                         if string.len(sContent) > 0 then |                         if #sContent > 0 then | ||||||
|                             send( "* " .. tUser.sUsername .. " " .. sContent ) |                             send( "* " .. tUser.sUsername .. " " .. sContent ) | ||||||
|                         else |                         else | ||||||
|                             send( "* Usage: /me [words]", tUser.nUserID ) |                             send( "* Usage: /me [words]", tUser.nUserID ) | ||||||
|                         end |                         end | ||||||
|                     end, |                     end, | ||||||
|                     ["nick"] = function( tUser, sContent ) |                     ["nick"] = function( tUser, sContent ) | ||||||
|                         if string.len(sContent) > 0 then |                         if #sContent > 0 then | ||||||
|                             local sOldName = tUser.sUsername |                             local sOldName = tUser.sUsername | ||||||
|                             tUser.sUsername = sContent |                             tUser.sUsername = sContent | ||||||
|                             send( "* " .. sOldName .. " is now known as " .. tUser.sUsername ) |                             send( "* " .. sOldName .. " is now known as " .. tUser.sUsername ) | ||||||
| @@ -199,7 +199,7 @@ if sCommand == "host" then | |||||||
|                                     if sCommand then |                                     if sCommand then | ||||||
|                                         local fnCommand = tCommands[ sCommand ] |                                         local fnCommand = tCommands[ sCommand ] | ||||||
|                                         if fnCommand then |                                         if fnCommand then | ||||||
|                                             local sContent = string.sub( sMessage, string.len(sCommand) + 3 ) |                                             local sContent = string.sub( sMessage, #sCommand + 3 ) | ||||||
|                                             fnCommand( tUser, sContent ) |                                             fnCommand( tUser, sContent ) | ||||||
|                                         else |                                         else | ||||||
|                                             send( "* Unrecognised command: /" .. sCommand, tUser.nUserID ) |                                             send( "* Unrecognised command: /" .. sCommand, tUser.nUserID ) | ||||||
| @@ -300,7 +300,7 @@ elseif sCommand == "join" then | |||||||
|         local w = titleWindow.getSize() |         local w = titleWindow.getSize() | ||||||
|         local sTitle = sUsername .. " on " .. sHostname |         local sTitle = sUsername .. " on " .. sHostname | ||||||
|         titleWindow.setTextColour( highlightColour ) |         titleWindow.setTextColour( highlightColour ) | ||||||
|         titleWindow.setCursorPos( math.floor( w / 2 - string.len(sTitle) / 2 ), 1 ) |         titleWindow.setCursorPos( math.floor( w / 2 - #sTitle / 2 ), 1 ) | ||||||
|         titleWindow.clearLine() |         titleWindow.clearLine() | ||||||
|         titleWindow.write( sTitle ) |         titleWindow.write( sTitle ) | ||||||
|         promptWindow.restoreCursor() |         promptWindow.restoreCursor() | ||||||
| @@ -321,7 +321,7 @@ elseif sCommand == "join" then | |||||||
|                 term.setTextColour( highlightColour ) |                 term.setTextColour( highlightColour ) | ||||||
|                 write( sUsernameBit ) |                 write( sUsernameBit ) | ||||||
|                 term.setTextColour( textColour ) |                 term.setTextColour( textColour ) | ||||||
|                 write( string.sub( sMessage, string.len( sUsernameBit ) + 1 ) ) |                 write( string.sub( sMessage, #sUsernameBit + 1 ) ) | ||||||
|             else |             else | ||||||
|                 write( sMessage ) |                 write( sMessage ) | ||||||
|             end |             end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jonathan Coates
					Jonathan Coates