aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-07-01 21:27:36 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-07-01 22:54:08 -0300
commitfbf60599a04cddab512e5e95165fe875d8c01303 (patch)
tree3ab25eff079068f01ce2d829932356b6b855c1f9 /src
parenta0e2ba8649305a0309edebd3cc74da23a39785d7 (diff)
downloadluarocks-fbf60599a04cddab512e5e95165fe875d8c01303.tar.gz
luarocks-fbf60599a04cddab512e5e95165fe875d8c01303.tar.bz2
luarocks-fbf60599a04cddab512e5e95165fe875d8c01303.zip
fun: add reverse_in and sort_in
* reverse_in: reverse table in-place * sort_in: sort table in-place
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/fun.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/luarocks/fun.lua b/src/luarocks/fun.lua
index 9ba02bf5..dfdf36ed 100644
--- a/src/luarocks/fun.lua
+++ b/src/luarocks/fun.lua
@@ -48,4 +48,19 @@ function fun.traverse(t, f)
48 end) 48 end)
49end 49end
50 50
51function fun.reverse_in(t)
52 for i = 1, math.floor(#t/2) do
53 local m, n = i, #t - i + 1
54 local a, b = t[m], t[n]
55 t[m] = b
56 t[n] = a
57 end
58 return t
59end
60
61function fun.sort_in(t, f)
62 table.sort(t, f)
63 return t
64end
65
51return fun 66return fun