[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Is this possible? (garbage collect and weak tables)
- From: Ignacio Burgueño <ignaciob@...>
- Date: Fri, 06 Nov 2009 10:08:27 -0200
module("translators", package.seeall)
local translators = {}
setmetatable(translators, {__mode = "v"})
local mt = {}
-- If there is not a suitable translator (for the given key and language),
-- create a new one and store it in a weak-valued table so it does not
-- linger there for ever.
mt.__index = function(tab, key)
local user = inconcert.authUser or {languageId=14346, codepage="UTF-8"}
--> translators[key] = translators[key] or {}
local translator = translators[key][user.languageId]
if not translator then
translator = i18nlib.Translator{domain=key, language =
user.languageId, codepage = user.codepage, transliterate=false}
--> translators[key][user.languageId] = translator
end
return translator
end
setmetatable(_M, mt)
A user reported the following error:
shared.render.cgiluaPage:
...les\inConcert\Web\data\lua\inconcert\translators.lua:20: attempt to
index field '?' (a nil value)
Line 20 is the second line in the code above marked with an arrow.
I guess that is possible that the GC kicks in between both marked lines,
so the table I put in the weak table went away, right?
Regards,
Ignacio Burgueño