33

Consider the following Lua code:

local var1, var2;

Is var2 a local variable here? Or is only var1 a local?

Phrogz
  • 296,393
  • 112
  • 651
  • 745
SirRatty
  • 2,338
  • 5
  • 25
  • 37

2 Answers2

32

Both are local.

lhf
  • 70,581
  • 9
  • 108
  • 149
24

Both variables are local, and both are given a value of nil.

To assign them to 2 different values, simply:

local var1,var2 = 1,2
Phrogz
  • 296,393
  • 112
  • 651
  • 745
Valerio Schiavoni
  • 1,373
  • 1
  • 12
  • 19
  • 3
    All variables are `nil` unless you give them some other value. That first line doesn't do anything different than the line in the original question. You're explicitly putting `nil` into var1 and implicitly putting it into `var`. If it worked the way you're describing, then `var1, var2 = 1` would put `1` into both variables. This is not the case. `var1` would be `1` and `var2` would be `nil`. – Cogwheel Jul 08 '10 at 18:48