Skip to content

Commit

Permalink
Merge pull request #4 from Tieske/master
Browse files Browse the repository at this point in the history
pack/unpack with 5.2 compat
  • Loading branch information
Etiene committed Mar 14, 2014
2 parents aedd49c + 99d5e85 commit 5c541c5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions valua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5c541c5

Please sign in to comment.