mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 13:42:59 +00:00 
			
		
		
		
	Make commands.collapseArgs a little more sane
We now generate a table and concatinate the elements together. This has several benefits: - We no longer emit emit trailing spaces, which caused issues on 1.13's command system. - We no longer need the error level variable, nor have the weird recursion system - it's just easier to understand.
This commit is contained in:
		| @@ -4,17 +4,20 @@ if not commands then | |||||||
| end | end | ||||||
| native = commands.native or commands | native = commands.native or commands | ||||||
|  |  | ||||||
| local function collapseArgs( errorDepth, bJSONIsNBT, arg1, ... ) | local function collapseArgs( bJSONIsNBT, ... ) | ||||||
|     if arg1 ~= nil then |     local args = table.pack(...) | ||||||
|         if type(arg1) == "boolean" or type(arg1) == "number" or type(arg1) == "string" then |     for i = 1, #args do | ||||||
|             return tostring(arg1) .. " " .. collapseArgs( errorDepth + 1, bJSONIsNBT, ... ) |         local arg = args[i] | ||||||
|         elseif type(arg1) == "table" then |         if type(arg) == "boolean" or type(arg) == "number" or type(arg) == "string" then | ||||||
|             return textutils.serialiseJSON( arg1, bJSONIsNBT ) .. " " .. collapseArgs( errorDepth + 1, bJSONIsNBT, ... ) |             args[i] = tostring(arg) | ||||||
|  |         elseif type(arg) == "table" then | ||||||
|  |             args[i] = textutils.serialiseJSON( arg, bJSONIsNBT ) | ||||||
|         else |         else | ||||||
|             error( "Expected string, number, boolean or table", errorDepth ) |             error( "Expected string, number, boolean or table", 3 ) | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
|     return "" |  | ||||||
|  |     return table.concat(args, " ") | ||||||
| end | end | ||||||
|  |  | ||||||
| -- Put native functions into the environment | -- Put native functions into the environment | ||||||
| @@ -34,11 +37,11 @@ for n,sCommandName in ipairs(tCommands) do | |||||||
|     if env[ sCommandName ] == nil then |     if env[ sCommandName ] == nil then | ||||||
|         local bJSONIsNBT = (tNonNBTJSONCommands[ sCommandName ] == nil) |         local bJSONIsNBT = (tNonNBTJSONCommands[ sCommandName ] == nil) | ||||||
|         env[ sCommandName ] = function( ... ) |         env[ sCommandName ] = function( ... ) | ||||||
|             local sCommand = sCommandName .. " " .. collapseArgs( 3, bJSONIsNBT, ... ) |             local sCommand = collapseArgs( bJSONIsNBT, sCommandName, ... ) | ||||||
|             return native.exec( sCommand ) |             return native.exec( sCommand ) | ||||||
|         end |         end | ||||||
|         tAsync[ sCommandName ] = function( ... ) |         tAsync[ sCommandName ] = function( ... ) | ||||||
|             local sCommand = sCommandName .. " " .. collapseArgs( 3, bJSONIsNBT, ... ) |             local sCommand = collapseArgs( bJSONIsNBT, sCommandName, ... ) | ||||||
|             return native.execAsync( sCommand ) |             return native.execAsync( sCommand ) | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 SquidDev
					SquidDev