wesnoth/data/ai/lua/cache.lua
Dmitry Kovalenko b9f9e29a0b LuaAI:
(1) fixed some naming inconsistencies;

(2) hidden some methods to the cache table, so that they don't lie
around unused in the ai table
2012-04-12 17:48:34 +00:00

24 lines
473 B
Lua

--! #textdomain wesnoth
return {
init = function(ai)
ai.cache = {}
ai.cache.data = {}
function ai.cache.update_cache(item, getter)
ai.cache.data[item] = ai.cache[getter]()
return ai.cache.data[item]
end
function ai.cache.get_cached_item(item, getter, validator)
if not ai.cache.data[item] or not ai.cache[validator]() then
local result = ai.cache.update_cache(item, getter)
return result
end
return ai.cache.data[item]
end
end
}