[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Upcoming changes in Lua 5.4
- From: "Soni \"They/Them\" L." <fakedme@...>
- Date: Tue, 2 Jan 2018 15:33:24 -0200
On 2018-01-02 03:21 PM, Michael Nelson wrote:
On 1/2/2018 6:18 AM, Roberto Ierusalimschy wrote: ...
I just love the new syntax. I assume select will continue to work as
usual, for old code and for use cases where it works better. The _ARG
name makes the parameter name for the main chunk consistent with Lua
_NAME practice, a good change. Any code broken by this last change
should be an easy fix: a simple search and replace.
As already explained, you can use _ARG; but you can use also any other
function foo (...=a) print(a.n) end
_ARG is present both for compatibility (the above syntax will not even
compile in older versions) and for the main chunk (which does not have
a header to name this parameter).
Hmm... Would the following work (and, if so, would it be faster than the
C API/built-in table.unpack)?
table.unpack = function(t, i, j)
assert(type(t) == "table", "first arg to table.unpack must be table")
i = i or 1
j = j or rawlen(t)
local oldn = rawget(t, "n")
rawset(t, "n", j)
local _ARG = t
local function helper(t, oldn, ...)
rawset(t, "n", oldn)
return helper(t, oldn, select(i, ...)) -- I guess this select() is
the limiting factor.
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.