checkTableDataTypes
Definition
-- @/lua/common/utils.lua:857
--usage: checkTableDataTypes(myTable, {"string", "number"}), returns true/false as first return and a text in case of failure as second
--only usable for array-typed tables
--add "optional:" in front one expected type to allow for "nil" in its place
function checkTableDataTypes(data, expectedTypes)
--check for number mismatch
if #data > #expectedTypes then
return false, string.format("Actual and expected parameter counts are mismatched, actual: %d, expected: %q", #data, #expectedTypes)
end
--check actual datatypes for expected types and report potential issues
for k, expectedType in ipairs(expectedTypes) do
local isOptional = expectedType:sub(0,9) == "optional:"
local sanitizedExpectedType = isOptional and expectedType:sub(10, #expectedType) or expectedType
local actualType = type(data[k])
local isDirectMatch = actualType == sanitizedExpectedType
if not (isDirectMatch or (isOptional and actualType == "nil")) then
return false, string.format("Wrong data type on param %d, expected: %q, actual: %q", k, expectedType, type(data[k]))
end
end
return true
end
Callers
@/lua/vehicle/controller/braking/transbrake.lua
if splits[1] == "controller" and (splits[2] == M.typeName or splits[2] == M.name) then
local dataTypeCheck, dataTypeError = checkTableDataTypes(eventData, {"string", "boolean"})
if not dataTypeCheck then
@/lua/common/utils.lua
--usage: checkTableDataTypes(myTable, {"string", "number"}), returns true/false as first return and a text in case of failure as second
--only usable for array-typed tables
@/lua/vehicle/extensions/gameplayInterfaceModules/interactController.lua
local function setFreeze(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"boolean"})
if not dataTypeCheck then
local function setGearboxMode(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"string"})
if not dataTypeCheck then
local function shiftToGearIndex(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"number"})
if not dataTypeCheck then
local function getMainControllerData(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"string"})
if not dataTypeCheck then
@/lua/vehicle/extensions/gameplayInterfaceModules/interactCargoContainers.lua
local function setCargoContainers(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"table", "string"})
if not dataTypeCheck then
local function getCargoContainers(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {})
if not dataTypeCheck then
@/lua/vehicle/extensions/gameplayInterfaceModules/interactVehiclePerformanceData.lua
local function startRecording(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"string", "optional:string", "optional:string", "optional:string", "optional:string"})
if not dataTypeCheck then
local function stopRecording(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"string", "optional:string", "optional:string", "optional:string", "optional:string"})
if not dataTypeCheck then
local function getRecordingData(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"string", "optional:string", "optional:string", "optional:string", "optional:string"})
if not dataTypeCheck then
local function getStaticData(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {})
if not dataTypeCheck then
@/lua/vehicle/extensions/gameplayInterfaceModules/interactFire.lua
local function interactFire(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, { "string" })
if not dataTypeCheck then
@/lua/vehicle/extensions/gameplayInterfaceModules/interactPowertrain.lua
local function getPowertrainDeviceData(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, { "string", "string" })
if not dataTypeCheck then
@/lua/vehicle/extensions/gameplayInterfaceModules/interactElectrics.lua
local function setIgnitionLevel(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"number"})
if not dataTypeCheck then
local function setLightbarMode(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"number"})
if not dataTypeCheck then
local function setLightMode(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"number"})
if not dataTypeCheck then
local function getElectricsData(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"string"})
if not dataTypeCheck then
@/lua/vehicle/extensions/gameplayInterfaceModules/interactEnergyStorage.lua
local function setEnergyStorageEnergy(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, { "string", "number" })
if not dataTypeCheck then
@/lua/vehicle/extensions/gameplayInterfaceModules/interactMisc.lua
local function ping(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {})
if not dataTypeCheck then
@/lua/vehicle/extensions/gameplayInterfaceModules/interactAI.lua
local function setAIMode(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, { "string" })
if not dataTypeCheck then
local function setOtherVehiclesAIMode(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, { "string" })
if not dataTypeCheck then
@/lua/vehicle/extensions/gameplayInterfaceModules/interactPartCondition.lua
local function initConditions(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"optional:table", "optional:number", "optional:number", "optional:number", "optional:table"})
if not dataTypeCheck then
local function ensureConditionsInit(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"number", "number", "number"})
if not dataTypeCheck then
local function getConditions(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {})
if not dataTypeCheck then
local function createConditionSnapshot(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"string"})
if not dataTypeCheck then
local function applyConditionSnapshot(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"string"})
if not dataTypeCheck then
local function deleteConditionSnapshots(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {})
if not dataTypeCheck then
local function setResetSnapshotKey(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"string"})
if not dataTypeCheck then
local function createAndSetPartConditionResetSnapshotKey(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"string"})
if not dataTypeCheck then
@/lua/vehicle/extensions/gameplayInterfaceModules/interactRecovery.lua
local function interactRecovery(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, { "string" })
if not dataTypeCheck then
@/lua/vehicle/extensions/gameplayInterfaceModules/interactBeamstate.lua
local function interactBeamstate(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"string"})
if not dataTypeCheck then
local function getBeamstateCouplerOffset(params)
local dataTypeCheck, dataTypeError = checkTableDataTypes(params, {"string"})
if not dataTypeCheck then