lua-users home
lua-l archive

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



On 07/05/2014 15:08, Daniel Stephens wrote:
Borrowing a trick from above, rearranging slightly, and some _G trickery - down to 253

local k,o,n,d=next,type,"table"d=function(a,r,t)if n~=o(a)then return a end t={}r=r or{}r[a]=t for x,y in k,a do x=r[x]or d(x,r)y=r[y]or d(y,r)t[x]=y end return t end _G[n].copy={shallow=function(a,b)b={}for x,y in k,a do b[x]=y end return b end,deep=d}


#"table" = 5
#"_G[n]" = 5

Really? (I also think the former may be faster, and more readable)

Also 246:
local k,o,n,d=next,type,"table"d=function(a,r,t)if n~=o(a)then return a end t={}r=r or{}r[a]=t for x,y in k,a do t[r[x]or d(x,r)]=r[y]or d(y,r)end return t end table.copy={shallow=function(a,b)b={}for x,y in k,a do b[x]=y end return b end,deep=d}