WoW:API unpack: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{tocright}}
{{tocright}}
Returns the values in a consecutive-integer indexed table
Returns the values in a consecutive-integer indexed table
  ret1, ret2, ... retN = unpack(table)
  ret1, ret2, ... retN = unpack(table[, start][, end])


Will not return values with hash style indexes.  For example:
Will not return values with hash style indexes.  For example:
Line 10: Line 10:
=== Parameters ===
=== Parameters ===
:;table: (table) - A table
:;table: (table) - A table
:;start: Integer - Starting index, defaults to 1 if nil
:;end: Integer - Ending index, appends nil values if the table does not contain enough


=== Returns ===
=== Returns ===
Line 19: Line 21:
  -- This does the same thing:
  -- This does the same thing:
  local arg1, arg2, arg3 = 1, 5, "Hearthstone"
  local arg1, arg2, arg3 = 1, 5, "Hearthstone"
unpack({1,2,3,4,5},2,7)  -- returns 2, 3, 4, 5, nil, nil


{{LUA}}
{{LUA}}

Revision as of 00:39, 17 September 2009

Returns the values in a consecutive-integer indexed table

ret1, ret2, ... retN = unpack(table[, start][, end])

Will not return values with hash style indexes. For example:

local t = {1, "two", "3", x = "ecks", y = "why?"}
unpack(t) -- returns: 1, "two", "3"

Arguments

Parameters

table
(table) - A table
start
Integer - Starting index, defaults to 1 if nil
end
Integer - Ending index, appends nil values if the table does not contain enough

Returns

ret1, ret2, ... retN
A list of the values contained in the given table.

Examples

local arg1, arg2, arg3 = unpack({1, 5, "Hearthstone"})

-- This does the same thing:
local arg1, arg2, arg3 = 1, 5, "Hearthstone"
unpack({1,2,3,4,5},2,7)  -- returns 2, 3, 4, 5, nil, nil

Template:LUA