lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Alex Davies wrote:
Right, easily possible - particularly if i18nlib.Translator makes a lot 
of allocations.  Easy enough to fix though, just save translators[key] 
to a local variable and restore it after the i18nlib call.
- Alex
Sadly, i18nlib.Translator allocates just a userdata wrapping a pointer 
(so 4 bytes for me).
Would this be safe?
local user = inconcert.authUser or {languageId=14346, codepage="UTF-8"}

local temp = translators[key] or {}	-- get a strong reference to the
					-- elements in the weak table	translators[key] = temp
local translator = temp[user.languageId]
if not translator then
	translator = i18nlib.Translator{(arguments omitted)}
	temp[user.languageId] = translator
end
return translator