Also true, function call overhead should not be ignored.
and select isn't the cheapest function to call =)
It's a lot cheaper than you might think at first (it surprised me the first time I looked at the implementation). It's not copying any of the [pointers-to-]values passed in. They're on the internal stack, and select() just decides where to chop off the stack:
static int luaB_select (lua_State *L) {
int n = lua_gettop(L);
if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {
lua_pushinteger(L, n-1);
return 1;
}
else {
int i = luaL_checkint(L, 1);
if (i < 0) i = n + i;
else if (i > n) i = n;
luaL_argcheck(L, 1 <= i, 1, "index out of range");
return n - i;
}
}
Sorry for the 2-space indents and the wonky brace style. It's not mine. :-)
[...]
If the initial argument is a number, it returns the subset of the list starting at that index:
select (3, a, b, c, d, e) --> c, d, e
In a variadic function, the expression '...' just expands to the list of stuff that got passed in at that spot in the parameter list, so you see a lot of use of select with '...' as the list of values.
How come the following code only returns the 3rd part of the index, and without those extra braces it returns the subset?
[COLOR="DarkGreen"](select(3,a,b,c,d,e))[/COLOR] --> c
not that it really matters since both will work if u just want c, but would it be slightly more memory efficient?
What Nev said. There are not a lot of places in addon programming where you specifically need to truncate expressions to a single value by using extra parenthesis.
Also remember that variable assignment will silently drop extra values, so for example, in
foo = select(3, a, b, c, d, e)
there's no need to wrap the select call in parens. Evaluation will go
The way Auracle does this is it uses a placeholder question-mark icon at first, and then the first time it sees the buff it's looking for, it remembers the icon texture (from UnitAura()). Then when the buff is missing in the future, it still has the icon texture name saved.
The advantage is you don't have to look up SpellIDs, you can just use buff names like you were planning on; the disadvantage is each thing you want to watch will have to be seen once for your addon to store its icon texture.
Yes, this is what I ended up doing. The convenience of being able to just enter buff names makes up for that slight disadvantage for me.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Very true.
Also true, function call overhead should not be ignored.
It's a lot cheaper than you might think at first (it surprised me the first time I looked at the implementation). It's not copying any of the [pointers-to-]values passed in. They're on the internal stack, and select() just decides where to chop off the stack:
Sorry for the 2-space indents and the wonky brace style. It's not mine. :-)
How come the following code only returns the 3rd part of the index, and without those extra braces it returns the subset?
not that it really matters since both will work if u just want c, but would it be slightly more memory efficient?
(a, b, c) --> a
It has some uses, but i don't think its particularly more efficient.
While we're at it, doing something like:
This will print "1, 4", because a variable length list can only be at the end of the argument list.
Also remember that variable assignment will silently drop extra values, so for example, in
there's no need to wrap the select call in parens. Evaluation will go
and then to
Yes, this is what I ended up doing. The convenience of being able to just enter buff names makes up for that slight disadvantage for me.