aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Richter <vrld@vrld.org>2013-01-23 12:23:10 +0100
committerMatthias Richter <vrld@vrld.org>2013-01-23 12:23:10 +0100
commit6f46983115ed2560e76b1f86fa4dd10ed21a3162 (patch)
treea4a43d7d29e68fed249e662ea3af26bf663010d8
parentfaa295651a86a9989bcafaecfa6b814694a72248 (diff)
downloadQuickie-6f46983115ed2560e76b1f86fa4dd10ed21a3162.tar.gz
Quickie-6f46983115ed2560e76b1f86fa4dd10ed21a3162.tar.bz2
Quickie-6f46983115ed2560e76b1f86fa4dd10ed21a3162.tar.xz
Quickie-6f46983115ed2560e76b1f86fa4dd10ed21a3162.zip
Proper tail recursion in core.save_unpack()
-rw-r--r--core.lua11
1 files changed, 7 insertions, 4 deletions
diff --git a/core.lua b/core.lua
index 3bc149f..67602ac 100644
--- a/core.lua
+++ b/core.lua
@@ -53,10 +53,13 @@ local function save_pack(...)
return {n = select('#', ...), ...}
end
-local function save_unpack(t, i)
- i = i or 1
- if i >= t.n then return t[i] end
- return t[i], save_unpack(t, i+1)
+local function save_unpack_helper(t, i, ...)
+ if i <= 0 then return ... end
+ return save_unpack_helper(t, i-1, t[i], ...)
+end
+
+local function save_unpack(t)
+ return save_unpack_helper(t, t.n)
end
--