lua-users home
lua-l archive

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


2015-06-15 15:26 GMT+02:00 Jinhua Luo <luajit.io@gmail.com>:

> Maybe the reference should describe more: "local" should be used
> once to declare new local variable (with different variable name).
> After all, the max number of local variables is limited due to the opcode
> format.

The manual says in §3.5:

    Notice that each execution of a local statement defines new local
    variables.

That implies that the code

local val = 1
local val = 1
local val = 1

will three times create a local variable called "val" and initialize it
to 1. This may be a silly, sloppy and stupid thing to do but it is not
illegal, and as "Rena" has pointed out, it is possible to write code
in which reusing the name is the intended behaviour.

As in many other places, the manual here says clearly and
unambiguously what it means, albeit with implications that might
be missed at first reading by a hasty reader.