WoW:API select: Difference between revisions

333 bytes added ,  18 December 2008
m
Cleanup
(Updated with new information - Added example function)
m (Cleanup)
Line 16: Line 16:


  -- Print all of the function's arguments (those passed to the ellipsis (...) only) to the default chat frame.
  -- Print all of the function's arguments (those passed to the ellipsis (...) only) to the default chat frame.
local msg
  for i = 1, select('#', ...) do
  for i = 1, select('#', ...) do
     DEFAULT_CHAT_FRAME:AddMessage(select(i, ...))
     msg = select(i, ...)
    DEFAULT_CHAT_FRAME:AddMessage(msg)
  end
  end


Line 29: Line 31:


  function MyAddon_Catenate(...)
  function MyAddon_Catenate(...)
local t,n,i,v;
    local t,v
    t = {}
n=select("#",...);
    for i = 1, select("#", ...) do
t={};
        v = select(i, ...)
for i=1,n do
        tinsert(t, v)
v=select(i, ...); -- Have to save to a variable before adding to get each element separately
    end
tinsert(t,v);
    return t
end
return t;
  end
  end


Line 49: Line 49:
: <pre>select(-1, 1, 2, 3, 4, 5) -- returns 5</pre>
: <pre>select(-1, 1, 2, 3, 4, 5) -- returns 5</pre>
* A decimal index will be rounded to the nearest integer (1.1 rounds to 1, 1.9 rounds to 2).
* A decimal index will be rounded to the nearest integer (1.1 rounds to 1, 1.9 rounds to 2).
* Passing a function that returns a list as a parameter to another function will pass each return as a parameter to the function as if you were manually passing each variable to that function, so ''tinsert(tab, select(1, ...))'', will have unpredictable results.
<pre>-- these are identical
-- number 1
local msg, r, g, b, a, id = select(1, ...)
DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b, a, id)


== Disclaimer ==
-- number 2
* Tested using the command line. Lua v5.1.2. Not tested in the WoW environment.
DEFAULT_CHAT_FRAME:AddMessage(select(1, ...))</pre>


{{LUA}}
{{LUA}}
Anonymous user