From 3bec7b356d74b345478907b98173cd7678ab8fb0 Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 7 Feb 2015 22:38:08 +0000 Subject: [PATCH] Added lume.push(), updated tests --- lume.lua | 9 +++++++++ test/test_lume.lua | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/lume.lua b/lume.lua index b19426a..e1b25c3 100644 --- a/lume.lua +++ b/lume.lua @@ -149,6 +149,15 @@ function lume.weightedchoice(t) end +function lume.push(t, ...) + local n = select("#", ...) + for i = 1, n do + t[#t + 1] = select(i, ...) + end + return ... +end + + function lume.shuffle(t) local rtn = {} for i = 1, #t do diff --git a/test/test_lume.lua b/test/test_lume.lua index 4c8dfca..1a4289b 100644 --- a/test/test_lume.lua +++ b/test/test_lume.lua @@ -106,6 +106,17 @@ tests["lume.weightedchoice"] = function() tester.test.error( lume.weightedchoice, { a = 1, b = -1 } ) end +-- lume.push +tests["lume.push"] = function() + local t = { 1, 2 } + lume.push(t, 3, 4) + testeq(t, { 1, 2, 3, 4 }) + lume.push(t, 5, nil, 6, nil, 7) + testeq(t, { 1, 2, 3, 4, 5, 6, 7 }) + lume.push(t) + testeq(t, { 1, 2, 3, 4, 5, 6, 7 }) +end + -- lume.shuffle tests["lume.shuffle"] = function() local t = {1, 2, 3, 4, 5}