util.cache: Make sure cache size is specified as an integer

This commit is contained in:
Kim Alvefur 2015-11-25 20:49:41 +01:00
parent c8454e9180
commit dd9e60beba

View file

@ -2,6 +2,8 @@ local cache_methods = {};
local cache_mt = { __index = cache_methods }; local cache_mt = { __index = cache_methods };
local function new(size) local function new(size)
size = assert(tonumber(size), "cache size must be a number");
size = math.floor(size);
assert(size > 0, "cache size must be greater than zero"); assert(size > 0, "cache size must be greater than zero");
local data = {}; local data = {};
return setmetatable({ data = data, count = 0, size = size, head = nil, tail = nil }, cache_mt); return setmetatable({ data = data, count = 0, size = size, head = nil, tail = nil }, cache_mt);