lua-users home
lua-l archive

Re: Why does lua interpreter need = in front of variables?

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


Matthew Wilson wrote:
I am learning lua after using python for the last few years.
In the lua toplevel, why do I either have to either put a "=" in front
of a variable?
In python, the toplevel evaluates everything automatically:
 $ python
 Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
 >>> 1 + 1
 2
 >>>
 $ lua
 Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
 > 1 + 1
 stdin:1: unexpected symbol near '1'
 > = 1 + 1
 2
 >
I started thinking about this, and I wondered if maybe the "=" forces
the toplevel to evaluate the object.
I'm just curious, but this detail stumps me.
The input "1 + 1" is not a full statement. It is just an expression. The Lua interpreter parses and executes full statements. The input "= 1 + 1" is shorthand for "return 1 + 1" which is a full statement. In addition, Lua interactive mode allows a statement to be multiple lines. For example:
 >lua
 Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
 > = 1 +
 >> 1
 2
 >

AltStyle によって変換されたページ (->オリジナル) /