From 13f886be5a6439df3357537f1d4b76e948714ab8 Mon Sep 17 00:00:00 2001 From: Wilma456 Date: Thu, 29 Jun 2017 16:41:48 +0200 Subject: [PATCH] Add Checks to disk,gps,help and keys --- .../resources/assets/computercraft/lua/rom/apis/disk.lua | 3 +++ .../resources/assets/computercraft/lua/rom/apis/gps.lua | 6 ++++++ .../resources/assets/computercraft/lua/rom/apis/help.lua | 9 +++++++++ .../resources/assets/computercraft/lua/rom/apis/keys.lua | 3 +++ 4 files changed, 21 insertions(+) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua b/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua index eda13773f..b5ae615fd 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua @@ -1,5 +1,8 @@ local function isDrive( name ) + if type( name ) ~= "string" then + error( "bad argument #1 (expected string, got " .. type( name ) .. ")", 3 ) + end return peripheral.getType( name ) == "drive" end diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua b/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua index eede2679a..6a83bf972 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua @@ -56,6 +56,12 @@ local function narrow( p1, p2, fix ) end function locate( _nTimeout, _bDebug ) + if _nTimeout ~= nil and type( _nTimeout ) ~= "number" then + error( "bad argument #1 (expected number, got " .. type( _nTimeout ) .. ")", 2 ) + end + if _bDebug ~= nil and type( _bDebug ) ~= "boolean" then + error( "bad argument #2 (expected boolean, got " .. type( _bDebug) .. ")", 2 ) + end -- Let command computers use their magic fourth-wall-breaking special abilities if commands then return commands.getBlockPosition() diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/help.lua b/src/main/resources/assets/computercraft/lua/rom/apis/help.lua index 64907fc48..5ce84081a 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/help.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/help.lua @@ -6,10 +6,16 @@ function path() end function setPath( _sPath ) + if type( _sPath ) ~= "string" then + error( "bad argument #1 (expected string, got " .. type( _sPath ) .. ")", 2 ) + end sPath = _sPath end function lookup( _sTopic ) + if type( _sTopic ) ~= "string" then + error( "bad argument #1 (expected string, got " .. type( _sTopic ) .. ")", 2 ) + end -- Look on the path variable for sPath in string.gmatch(sPath, "[^:]+") do sPath = fs.combine( sPath, _sTopic ) @@ -57,6 +63,9 @@ function topics() end function completeTopic( sText ) + if type( sText ) ~= "string" then + error( "bad argument #1 (expected string, got " .. type( sText ) .. ")", 2 ) + end local tTopics = topics() local tResults = {} for n=1,#tTopics do diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/keys.lua b/src/main/resources/assets/computercraft/lua/rom/apis/keys.lua index 98da2a4e0..8b8342500 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/keys.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/keys.lua @@ -55,5 +55,8 @@ end keys["return"] = keys.enter function getName( _nKey ) + if type( _nKey ) ~= "number" then + error( "bad argument #1 (expected number, got " .. type( _nKey ) .. ")", 2 ) + end return tKeys[ _nKey ] end