lua-users home
lua-l archive

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


2016-06-21 2:20 GMT+02:00 Roberto Ierusalimschy <roberto@inf.puc-rio.br>:
>> Could you explain why that happens? luaB_select is clearly O(1).
>> Does VARARG copy the arguments?
>
> Yes.
>
>
>> If so, why is that necessary?
>
> Any function call in Lua copies the arguments to the stack frame of
> the new function being called. You are all invited to do a better
> implementation.

One way is to make available the syntax `#...` and `...[k]` which would
not be syntactic sugar for `select` but would generate a VM instruction
VARARGK A B that puts into R(A) the k-th vararg (where k is computed
from R(B) with the usual rule for negative values) or the vararg length
of k=0. Of course, `...[k]=a` would still be illegal.