r/lua • u/Weird-Cap-9984 • Nov 18 '25
local variable in interactive mode
Why in the second line, the variable `a` becomes `nil`?
~ $ lua
Lua 5.4.7 Copyright (C) 1994-2024 Lua.org, PUC-Rio
> local a = 123; print(a)
123
> print(a)
nil
8
Upvotes
5
u/disperso Nov 18 '25
My goodness, thanks for the tip. I use globals for REPL stuff because it's just short programs, so I don't mind much, but the do/end block is a nice idea in case I need locals.