lua-users home
lua-l archive

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


On Wed, Jul 4, 2018 at 5:43 PM, Alexander Mokrushyn
<codeservice@gmail.com> wrote:
> Would be nice have conception of namespace. Namespace always global, in
> every programming language.
>
> Code can look like:
>
> namespace MyNamespace
>    a = 1
>
>    function fn1()
>    end
> end
>
> and if I load code as package, I can access to "a" or function:
>
> print(MyNamespace.a)
> MyNamespace.fn1()

You can already do exactly that with _ENV:

MyNamespace = {}
do
   _ENV = MyNamespace
   ...
end