lua-users home
lua-l archive

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

>From what I know the reason is that Lua was designed as
a simple configuration language where it is desirable to
have all variables global by default.

Unfortunately, this makes Lua less suitable for larger

According to Luiz the main reason for current behavior is
that in case of opposite it would be necessary to declare
all functions as global. Probably the design of Lua does
not allow to determine variable scope by the block where
it is declared. It's a pitty because in my opinion it would
be very nice solution - if a function is defined in global scope,
it exists until global scope is destroyed and if a function
or a variable is defined in a block, it exists until execution
of the block reaches its "End".


> >How hard would it be to modify Lua source code
> >to add "global" keyword for explicit declaration
> >of global variables and make all variables local
> >by default?
> This is one thing I never understood. Why is it implemented that way - in
> all other programming languages (that I know) variables in
> subroutines/functions are automatically local. Is there a reason, why it
> is implemented the other way round?