lua-users home
lua-l archive

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


Yes, only _ENV looks like hardly readable code.

namespace MyNamespace - more clean

and can look even more readable with:

use MyNamespace
print(a)
fn1()


For me _ENV works too, only some time code in Lua looks like regular expressions, powerful but hard to read :)


On Wed, Jul 4, 2018 at 4:56 PM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
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