Fandom

WoWWiki

USERAPI allAreType

104,630pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

This page documents a user-defined function that you can copy and paste into your addon. Replace <PREFIX> with your AddOn's prefix to avoid conflicts between different versions of these functions.
User defined functions < allAreType

This function is designed to make long If statements quicker and easier. Allows you to check lots of values at once for the same type

<PREFIX>_allAreType(type, param [,param [, ...]])

Note:

If just the type parameter is given then the function returns true, as no parameters have failed the check (See example 'c' below).

Function Parameters Edit

Arguments Edit

type
String - A string that represents the desired type of the values. See type() for further help on this value.
param
any - A list of values to check for the same, consistent type.

Returns Edit

result
Boolean - true if all of the params have the desired type, false if atleast one fails.

Example Edit

local a = <PREFIX>_allAreType("string", "Hello", DEFAULT_CHAT_FRAME:GetName())
local b = <PREFIX>_allAreType("number", 65, tonumber("two"))
local c = <PREFIX>_allAreType("table", {}, {5, 3, "Hello"}, "Bob")

-- edge cases
local d = <PREFIX>_allAreType("function")
local e = <PREFIX>_allAreType("function", nil)

ResultEdit

a = true
b = false
c = false

-- edge cases
d = true
e = false

CodeEdit

function <PREFIX>_allAreType(typeStr, ...)
  local value
  for i = 1, select('#', ...) do
    value = select(i, ...)
    if type(value) ~= typeStr then
      return false
    end
  end
  return true
end

Also on Fandom

Random Wiki