[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Feature Suggestion: Make select('#', ...) instead "prepend" gettop() at stack index 1 and return the lot (args included)
- From: Sir Pogsalot <sir.pogsalot@...>
- Date: Wed, 27 Jun 2012 18:41:12 -0700
Currently select('#', 1, 2, 3) will of course only return 3, but imo it would be nicer if simply prepended the varargs with the gettop() value and returned it like so: 3, 1, 2, 3
This is useful when I write a function where I want to avoid a table construction but also want to know how many args were passed:
local n, cat, dog, horse = select('#', ...), ...
Bad example I know, but even if you don't believe in its practicality, I believe it would make more efficient use of stack space to "recycle" the varargs passed originally to select() than to seemingly reload them onto the stack again after for the later assignments.
Perhaps I'm wrong, I haven't tested this -- it only makes sense in my head (where 2 + 2 does equal 5) :(
daurnimator in #lua imagined it like:
lua_pushinteger(L, lua_gettop(L) - 1);
lua_replace(L,1);
return lua_gettop(L);
Please and thank you :x