Lua modules - strange behaviour

Hello!

In my Game i created a lua module which handles the languagestuff. It looks like this:

File Language.lua

LanguageManager = {}
LanguageManager.locale = nil
LanguageManager.loadedText= nil

function LanguageManager:initialize()

end

function LanguageManager:getString(key)
– some other functions …

return LanguageManager

Okay, I am using it like this require(“Language”):getString(“language.key”). The getString(key) method is looking if the LanguageManager is initialized (e.g locale is set). If it is not set, the initialized-method is called, a textfile is loaded and the keys are saved in LanguageManager.loadedText.

It works totally nice when staying in the same scene. I loaded anoter scene and replaced the Scene via cc:Director(). When using the Languagemodule again, initialize is called! But why? I thought the require Lua mechanism is only loaded once and require will always get the same module.

I hope you can help me. Thanks!

@samuele3hu could you pls take a look?

I also tried it with pushScene instead of replaceScene because I thought when the scene is replaced, memory is also given free. But that’s not the case. Same behaviour with pushScene :frowning:

Yeah,Can you give me the simple demo to reproduce it.If “Language” package was loaded,it would be save in the package.loaded.

wtf … I tried a new small project and there it works … Now I need to find out why it isn’t working in my big project -.- Maybe I can contact you later if I find something…
edit
meh… the error was so simple…
In one file I did:

require("frontend/utils/Language.lua"):getString("menuscene.startGame")

which is saved in package.loaded[“frontend/utils/Language.lua”].
In another file I used it like this

require("frontend/utils/Language"):getString("menuscene.startGame")?

which isn’t exactly the same and it is created new …