mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-12 11:10:29 +00:00
Add Checks to Textutils API
This commit is contained in:
parent
174b63d59a
commit
6bbd1f3718
@ -25,6 +25,12 @@ function slowPrint( sText, nRate )
|
|||||||
end
|
end
|
||||||
|
|
||||||
function formatTime( nTime, bTwentyFourHour )
|
function formatTime( nTime, bTwentyFourHour )
|
||||||
|
if type( nTime ) ~= "number" then
|
||||||
|
error( "bad argument #1 (expected number, got " .. type( nTime ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
if bTwentyFourHour ~= nil and type( bTwentyFourHour ) ~= "boolean" then
|
||||||
|
error( "bad argument #2 (expected boolean, got " .. type( bTwentyFourHour ) .. ")", 2 )
|
||||||
|
end
|
||||||
local sTOD = nil
|
local sTOD = nil
|
||||||
if not bTwentyFourHour then
|
if not bTwentyFourHour then
|
||||||
if nTime >= 12 then
|
if nTime >= 12 then
|
||||||
@ -68,6 +74,9 @@ local function makePagedScroll( _term, _nFreeLines )
|
|||||||
end
|
end
|
||||||
|
|
||||||
function pagedPrint( _sText, _nFreeLines )
|
function pagedPrint( _sText, _nFreeLines )
|
||||||
|
if _nFreeLines ~= nil and type( _nFreeLines ) ~= "number" then
|
||||||
|
error( "bad argument #2 (expected number, got " .. type( _nFreeLines ) .. ")", 2 )
|
||||||
|
end
|
||||||
-- Setup a redirector
|
-- Setup a redirector
|
||||||
local oldTerm = term.current()
|
local oldTerm = term.current()
|
||||||
local newTerm = {}
|
local newTerm = {}
|
||||||
@ -149,10 +158,32 @@ local function tabulateCommon( bPaged, ... )
|
|||||||
end
|
end
|
||||||
|
|
||||||
function tabulate( ... )
|
function tabulate( ... )
|
||||||
|
tArgs = { ... }
|
||||||
|
for i=1,#tArgs,2 do
|
||||||
|
if type( tArgs[i] ) ~= "number" then
|
||||||
|
error( "bad argument #"..i.." (expected number, got " .. type( tArgs[i] ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i=2,#tArgs,2 do
|
||||||
|
if type( tArgs[i] ) ~= "table" then
|
||||||
|
error( "bad argument #"..i.." (expected table, got " .. type( tArgs[i] ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
end
|
||||||
tabulateCommon( false, ... )
|
tabulateCommon( false, ... )
|
||||||
end
|
end
|
||||||
|
|
||||||
function pagedTabulate( ... )
|
function pagedTabulate( ... )
|
||||||
|
tArgs = { ... }
|
||||||
|
for i=1,#tArgs,2 do
|
||||||
|
if type( tArgs[i] ) ~= "number" then
|
||||||
|
error( "bad argument #"..i.." (expected number, got " .. type( tArgs[i] ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i=2,#tArgs,2 do
|
||||||
|
if type( tArgs[i] ) ~= "table" then
|
||||||
|
error( "bad argument #"..i.." (expected table, got " .. type( tArgs[i] ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
end
|
||||||
tabulateCommon( true, ... )
|
tabulateCommon( true, ... )
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -301,6 +332,9 @@ function serialize( t )
|
|||||||
end
|
end
|
||||||
|
|
||||||
function unserialize( s )
|
function unserialize( s )
|
||||||
|
if type( s ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( s ) .. ")", 2 )
|
||||||
|
end
|
||||||
local func = load( "return "..s, "unserialize", "t", {} )
|
local func = load( "return "..s, "unserialize", "t", {} )
|
||||||
if func then
|
if func then
|
||||||
local ok, result = pcall( func )
|
local ok, result = pcall( func )
|
||||||
@ -312,11 +346,20 @@ function unserialize( s )
|
|||||||
end
|
end
|
||||||
|
|
||||||
function serializeJSON( t, bNBTStyle )
|
function serializeJSON( t, bNBTStyle )
|
||||||
|
if type( t ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( t ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
if bNBTStyle ~= nil and type( bNBTStyle ) ~= "boolean" then
|
||||||
|
error( "bad argument #2 (expected boolean, got " .. type( bNBTStyle ) .. ")", 2 )
|
||||||
|
end
|
||||||
local tTracking = {}
|
local tTracking = {}
|
||||||
return serializeJSONImpl( t, tTracking, bNBTStyle or false )
|
return serializeJSONImpl( t, tTracking, bNBTStyle or false )
|
||||||
end
|
end
|
||||||
|
|
||||||
function urlEncode( str )
|
function urlEncode( str )
|
||||||
|
if type( str ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( str ) .. ")", 2 )
|
||||||
|
end
|
||||||
if str then
|
if str then
|
||||||
str = string.gsub(str, "\n", "\r\n")
|
str = string.gsub(str, "\n", "\r\n")
|
||||||
str = string.gsub(str, "([^A-Za-z0-9 %-%_%.])", function(c)
|
str = string.gsub(str, "([^A-Za-z0-9 %-%_%.])", function(c)
|
||||||
@ -338,6 +381,12 @@ end
|
|||||||
|
|
||||||
local tEmpty = {}
|
local tEmpty = {}
|
||||||
function complete( sSearchText, tSearchTable )
|
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
|
||||||
|
error( "bad argument #2 (expected table, got " .. type( tSearchTable ) .. ")", 2 )
|
||||||
|
end
|
||||||
local nStart = 1
|
local nStart = 1
|
||||||
local nDot = string.find( sSearchText, ".", nStart, true )
|
local nDot = string.find( sSearchText, ".", nStart, true )
|
||||||
local tTable = tSearchTable or _ENV
|
local tTable = tSearchTable or _ENV
|
||||||
|
Loading…
Reference in New Issue
Block a user