mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-04-10 20:56:40 +00:00
Fix some textutils API argument checks made in PR #338
- textutils.serializeJSON now takes a table/string/number/boolean instead of just a string as the t argument, and checks for nil in the tNBTStyle argument, so the parameter becomes optional again, as described in the wiki. - textutils.slowWrite and textutils.slowPrint now checks if the rate parameter is a number, if not nil.
This commit is contained in:
parent
94d701b1f7
commit
7e5a9b3a5a
@ -1,5 +1,8 @@
|
||||
|
||||
function slowWrite( sText, nRate )
|
||||
if nRate ~= nil and type( nRate ) ~= "number" then
|
||||
error( "bad argument #2 (expected number, got " .. type( nRate ) .. ")", 2 )
|
||||
end
|
||||
nRate = nRate or 20
|
||||
if nRate < 0 then
|
||||
error( "Rate must be positive", 2 )
|
||||
@ -20,7 +23,7 @@ function slowWrite( sText, nRate )
|
||||
end
|
||||
|
||||
function slowPrint( sText, nRate )
|
||||
slowWrite( sText, nRate)
|
||||
slowWrite( sText, nRate )
|
||||
print()
|
||||
end
|
||||
|
||||
@ -329,11 +332,11 @@ function unserialize( s )
|
||||
end
|
||||
|
||||
function serializeJSON( t, bNBTStyle )
|
||||
if type( t ) ~= "string" then
|
||||
error( "bad argument #1 (expected string, got " .. type( t ) .. ")", 2 )
|
||||
if type( t ) ~= "table" or type( t ) == "string" or type( t ) == "number" or type( t ) == "boolean" then
|
||||
error( "bad argument #1 (expected table/string/number/boolean, got " .. type( t ) .. ")", 2 )
|
||||
end
|
||||
if bNBTStyle ~= nil and type( bNBTStyle ) ~= "boolean" then
|
||||
error( "bad argument #2 (expected boolean, got " .. type( bNBTStyle ) .. ")", 2 )
|
||||
error( "bad argument #2 (expected boolean, got " .. type( bNBTStyle ) .. ")", 2 )
|
||||
end
|
||||
local tTracking = {}
|
||||
return serializeJSONImpl( t, tTracking, bNBTStyle or false )
|
||||
@ -367,7 +370,7 @@ function complete( sSearchText, tSearchTable )
|
||||
if type( sSearchText ) ~= "string" then
|
||||
error( "bad argument #1 (expected string, got " .. type( sSearchText ) .. ")", 2 )
|
||||
end
|
||||
if type( tSearchTable ) ~= "table" then
|
||||
if tSearchTable ~= nil and type( tSearchTable ) ~= "table" then
|
||||
error( "bad argument #2 (expected table, got " .. type( tSearchTable ) .. ")", 2 )
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user