util.cache: Make sure cache size is specified as an integer
authorKim Alvefur <zash@zash.se>
Wed, 25 Nov 2015 20:49:41 +0100
changeset 6946 0a31ec3193f0
parent 6945 f12deb882148
child 6947 62b6f6d230f1
util.cache: Make sure cache size is specified as an integer
util/cache.lua
--- a/util/cache.lua	Wed Nov 25 20:43:29 2015 +0100
+++ b/util/cache.lua	Wed Nov 25 20:49:41 2015 +0100
@@ -2,6 +2,8 @@
 local cache_mt = { __index = cache_methods };
 
 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");
 	local data = {};
 	return setmetatable({ data = data, count = 0, size = size, head = nil, tail = nil }, cache_mt);