From 99d5e856f9831d6e999141e75584caaaa89ef50a Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 14 Mar 2014 11:23:22 +0100 Subject: pack/unpack with 5.2 compat `unpack` was renamed `table.unpack` in Lua 5.2. This way is 5.1/5.2 agnostic --- valua.lua | 7 ++++--- 1 file 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 _ 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 -- cgit v1.2.3-70-g09d2