mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-11 18:00:29 +00:00
Add more Checks
This commit is contained in:
parent
579f7443a8
commit
e9cea7d0f5
@ -709,6 +709,9 @@ if http then
|
||||
if _headers ~= nil and type( _headers ) ~= "table" then
|
||||
error( "bad argument #2 (expected table, got " .. type( _headers ) .. ")", 2 )
|
||||
end
|
||||
if _binary ~= nil and type( _binary ) ~= "boolean" then
|
||||
error( "bad argument #3 (expected boolean, got " .. type( _binary ) .. ")", 2 )
|
||||
end
|
||||
return wrapRequest( _url, nil, _headers, _binary)
|
||||
end
|
||||
|
||||
@ -722,6 +725,9 @@ if http then
|
||||
if _headers ~= nil and type( _headers ) ~= "table" then
|
||||
error( "bad argument #3 (expected table, got " .. type( _headers ) .. ")", 2 )
|
||||
end
|
||||
if _binary ~= nil and type( _binary ) ~= "boolean" then
|
||||
error( "bad argument #4 (expected boolean, got " .. type( _binary ) .. ")", 2 )
|
||||
end
|
||||
return wrapRequest( _url, _post or "", _headers, _binary)
|
||||
end
|
||||
|
||||
@ -735,6 +741,9 @@ if http then
|
||||
if _headers ~= nil and type( _headers ) ~= "table" then
|
||||
error( "bad argument #3 (expected table, got " .. type( _headers ) .. ")", 2 )
|
||||
end
|
||||
if _binary ~= nil and type( _binary ) ~= "boolean" then
|
||||
error( "bad argument #4 (expected boolean, got " .. type( _binary ) .. ")", 2 )
|
||||
end
|
||||
local ok, err = nativeHTTPRequest( _url, _post, _headers, _binary )
|
||||
if not ok then
|
||||
os.queueEvent( "http_failure", _url, err )
|
||||
|
@ -49,11 +49,14 @@ function input( _arg )
|
||||
elseif _G.type( _arg ) == "nil" then
|
||||
return g_currentInput
|
||||
else
|
||||
error( "Expected file name or file handle" )
|
||||
error( "bad argument #1 (expected string/table/nil, got " .. type( _arg ) .. ")", 2 )
|
||||
end
|
||||
end
|
||||
|
||||
function lines( _sFileName )
|
||||
if type( _sFileNamel ) ~= "string" then
|
||||
error( "bad argument #1 (expected string, got " .. type( _sFileName ) .. ")", 2 )
|
||||
end
|
||||
if _sFileName then
|
||||
return open( _sFileName, "r" ):lines()
|
||||
else
|
||||
@ -62,6 +65,12 @@ function lines( _sFileName )
|
||||
end
|
||||
|
||||
function open( _sPath, _sMode )
|
||||
if type( _sPath ) ~= "string" then
|
||||
error( "bad argument #1 (expected string, got " .. type( _sPath ) .. ")", 2 )
|
||||
end
|
||||
if type( _sMode ) ~= "string" then
|
||||
error( "bad argument #2 (expected string, got " .. type( _sMode ) .. ")", 2 )
|
||||
end
|
||||
local sMode = _sMode or "r"
|
||||
local file = fs.open( _sPath, sMode )
|
||||
if not file then
|
||||
@ -158,7 +167,7 @@ function output( _arg )
|
||||
elseif _G.type( _arg ) == "nil" then
|
||||
return g_currentOutput
|
||||
else
|
||||
error( "Expected file name or file handle" )
|
||||
error( "bad argument #1 (expected string/table/nil, got " .. type( _arg ) .. ")", 2 )
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -8,7 +8,7 @@ local tHostnames = {}
|
||||
|
||||
function open( sModem )
|
||||
if type( sModem ) ~= "string" then
|
||||
error( "expected string", 2 )
|
||||
error( "bad argument #1 (expected string, got " .. type( sModem ) .. ")", 2 )
|
||||
end
|
||||
if peripheral.getType( sModem ) ~= "modem" then
|
||||
error( "No such modem: "..sModem, 2 )
|
||||
@ -21,7 +21,7 @@ function close( sModem )
|
||||
if sModem then
|
||||
-- Close a specific modem
|
||||
if type( sModem ) ~= "string" then
|
||||
error( "expected string", 2 )
|
||||
error( "bad argument #1 (expected string, got " .. type( sModem ) .. ")", 2 )
|
||||
end
|
||||
if peripheral.getType( sModem ) ~= "modem" then
|
||||
error( "No such modem: "..sModem, 2 )
|
||||
@ -42,7 +42,7 @@ function isOpen( sModem )
|
||||
if sModem then
|
||||
-- Check if a specific modem is open
|
||||
if type( sModem ) ~= "string" then
|
||||
error( "expected string", 2 )
|
||||
error( "bad argument #1 (expected string, got " .. type( sModem ) .. ")", 2 )
|
||||
end
|
||||
if peripheral.getType( sModem ) == "modem" then
|
||||
return peripheral.call( sModem, "isOpen", os.getComputerID() ) and peripheral.call( sModem, "isOpen", CHANNEL_BROADCAST )
|
||||
@ -59,6 +59,12 @@ function isOpen( sModem )
|
||||
end
|
||||
|
||||
function send( nRecipient, message, sProtocol )
|
||||
if type( nRecipient ) ~= "number" then
|
||||
error( "bad argument #1 (expected number, got " .. type( nRecipient ) .. ")", 2 )
|
||||
end
|
||||
if sProtocol ~= nil and type( sProtocol ) ~= "string" then
|
||||
error( "bad argument #3 (expected string, got " .. type( sProtocol ) .. ")", 2 )
|
||||
end
|
||||
-- Generate a (probably) unique message ID
|
||||
-- We could do other things to guarantee uniqueness, but we really don't need to
|
||||
-- Store it to ensure we don't get our own messages back
|
||||
@ -93,10 +99,19 @@ function send( nRecipient, message, sProtocol )
|
||||
end
|
||||
|
||||
function broadcast( message, sProtocol )
|
||||
if sProtocol ~= nil and type( sProtocol ) ~= "string" then
|
||||
error( "bad argument #2 (expected string, got " .. type( sProtocol ) .. ")", 2 )
|
||||
end
|
||||
send( CHANNEL_BROADCAST, message, sProtocol )
|
||||
end
|
||||
|
||||
function receive( sProtocolFilter, nTimeout )
|
||||
if sProtocolFilter ~= nil and type( sProtocolFilter ) ~= "string" then
|
||||
error( "bad argument #1 (expected string, got " .. type( sProtocolFilter ) .. ")", 2 )
|
||||
end
|
||||
if nTimeout ~= nil and type( nTimeoutl ) ~= "number" then
|
||||
error( "bad argument #2 (expected number, got " .. type( nTimeout ) .. ")", 2 )
|
||||
end
|
||||
-- The parameters used to be ( nTimeout ), detect this case for backwards compatibility
|
||||
if type(sProtocolFilter) == "number" and nTimeout == nil then
|
||||
sProtocolFilter, nTimeout = nil, sProtocolFilter
|
||||
@ -131,8 +146,11 @@ function receive( sProtocolFilter, nTimeout )
|
||||
end
|
||||
|
||||
function host( sProtocol, sHostname )
|
||||
if type( sProtocol ) ~= "string" or type( sHostname ) ~= "string" then
|
||||
error( "expected string, string", 2 )
|
||||
if type( sProtocol ) ~= "string" then
|
||||
error( "bad argument #1 (expected string, got " .. type( sProtocol ) .. ")", 2 )
|
||||
end
|
||||
if type( sHostname ) ~= "string" then
|
||||
error( "bad argument #2 (expected string, got " .. type( sHostname ) .. ")", 2 )
|
||||
end
|
||||
if sHostname == "localhost" then
|
||||
error( "Reserved hostname", 2 )
|
||||
@ -147,14 +165,17 @@ end
|
||||
|
||||
function unhost( sProtocol )
|
||||
if type( sProtocol ) ~= "string" then
|
||||
error( "expected string", 2 )
|
||||
error( "bad argument #1 (expected string, got " .. type( sProtocol ) .. ")", 2 )
|
||||
end
|
||||
tHostnames[ sProtocol ] = nil
|
||||
end
|
||||
|
||||
function lookup( sProtocol, sHostname )
|
||||
if type( sProtocol ) ~= "string" then
|
||||
error( "expected string", 2 )
|
||||
error( "bad argument #1 (expected string, got " .. type( sProtocol ) .. ")", 2 )
|
||||
end
|
||||
if type( sHostname ) ~= "string" then
|
||||
error( "bad argument #2 (expected string, got " .. type( sHostname ) .. ")", 2 )
|
||||
end
|
||||
|
||||
-- Build list of host IDs
|
||||
|
Loading…
Reference in New Issue
Block a user