lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Jul 14, 2016 at 2:01 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
Am 14.07.2016 um 10:13 schröbte Egor Skriptunoff:
On Thu, Jul 14, 2016 at 11:01 AM, Daurnimator <quae@daurnimator.com> wrote:

Maybe, {1, 2, 3} for tables, @{1, 2, 3} for arrays (with array metatable
applied)?

In that case, why not use the already valid: S(1,2,3)

Three reasons:
1) Standardization of array type in Lua (all the developers will use the
same implementation of arrays)
2) Avoidance of performance penalty due to passing vararg to a function

What performance penalty?

Lua pushes all the arguments to the stack to invoke S(1,2,3),
and inside S() Lua pushes them AGAIN for constructing a table.
"VARARG" bytecode is not O(1) instruction, it was discussed earlier in this list.

Moreover, S(1,2,3) does not work for arrays longer than 256 elements.

 
`f@{ 1, 2, 3 }` isn't that much better, though ...
 
Quite nice with a space between :-)
func @{1,2,3}