lua-users home
lua-l archive

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


Sometimes I need to share o variable among submodules inside the same package.
It would be great if existed a module variable _P for the current package, just like _M is for the current module.

My current simple solution is to create a global variable in the base module ( init.lua):
_G._P = _M

If I don't have a base file I have to do:
_M._P = _G[string.sub(_PACKAGE,1,-2)] -- remove the leading dot

I'm not sure about package's actual name because I usually create modules as:
module ((...))

Is there a better solution?
(few lines, not polluting global space?)