lua-users home
lua-l archive

Re: Reverse

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


2014年08月01日 20:20 GMT+02:00 Thiago L. <fakedme@gmail.com>:
>
> What about tables?
>
Not too hard to do in Lua itself.
function reverse(tbl)
 local k,n=1,#tbl
 while k<n do
 tbl[k],tbl[n] = tbl[n],tbl[k]
 k,n = k+1,n-1
 end
end
Under the new dispensation, with metamethods respected,
I even doubt whether doing it in Lua takes much of
a performance hit.

AltStyle によって変換されたページ (->オリジナル) /