Изменения

serialise
Строка 40: Строка 40:     
local function memoize (func)
 
local function memoize (func)
 +
local function serialise_args (...)
 +
local serialised = {}
 +
for _, arg in ipairs {...} do
 +
serialised [#serialised + 1] = serialise (arg)
 +
end
 +
return concat (serialised)
 +
end
 
local memoized = {}
 
local memoized = {}
 
return function (...)
 
return function (...)
--local key = tostring (setmetatable ({...}, { __tostring = serialise }))
+
local key = serialise_args {...}
local key = concat {...}
   
if not memoized [key] then
 
if not memoized [key] then
 
memoized [key] = { func (...) }
 
memoized [key] = { func (...) }