aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEtiene <Etiene@users.noreply.github.com>2014-03-14 13:16:53 -0300
committerEtiene <Etiene@users.noreply.github.com>2014-03-14 13:16:53 -0300
commit5c541c55c1a16469ef7ed1c34de2511f6916c6a3 (patch)
treeece004c0799cfdfe6f1fa5d43eae3bdb0767b05f
parentaedd49c245416c1682c26820d77c31a3d1b98d67 (diff)
parent99d5e856f9831d6e999141e75584caaaa89ef50a (diff)
downloadvalua-0.2.2.tar.gz
valua-0.2.2.tar.bz2
valua-0.2.2.zip
Merge pull request #4 from Tieske/master0.2.2
pack/unpack with 5.2 compat
-rw-r--r--valua.lua7
1 files changed, 4 insertions, 3 deletions
diff --git a/valua.lua b/valua.lua
index dad5a65..435041e 100644
--- a/valua.lua
+++ b/valua.lua
@@ -23,6 +23,8 @@ local valua = {}
local tinsert,setmetatable,len,match,tonumber = table.insert,setmetatable,string.len,string.match,tonumber
local next,type,floor,ipairs = next,type,math.floor, ipairs
+local unpack = unpack or table.unpack
+local pack = table.pack or function(...) return { n = select('#', ...), ... } end
-- CORE
-- Caution, this is confusing
@@ -35,9 +37,8 @@ function valua:new(obj)
self.__index = function(t,k)
--saves a function named _<index> with its args in a funcs table, to be used later when validating
return function(...)
- local args = {...}
- local n = select("#", ...)
- local f = function(value) return valua['_'..k](value, unpack(args, 1, n)) end
+ local args = pack(...)
+ local f = function(value) return valua['_'..k](value, unpack(args, 1, args.n)) end
tinsert(t.funcs,f)
return t
end