Can I run Lua interpreter in evaluator mode?
-
16-04-2021 - |
سؤال
Many of script interpreters like irb
or node
works as evaluator. If I execute this code,
10
it will evaluate and print the value itself, and make no error.
When I installed lua
it worked as executor rather than evaluator. So when I put 10
, it will make an error.
Can I make the Lua interpreter work as evaluator?
المحلول
There's also iLua. It is an extended interpreter and does pretty much all you want.
نصائح أخرى
There is no such thing as "evaluator mode". The Lua interpreter only interprets valid Lua code. That is except for one exception, that is lines starting with =
.
In the stand alone interpreter, you have this shortcut to start a line with =
, which translates to return
. And in the interpreter, when a value gets returned to the "main" routine, it gets printed.
So these are effectively equivalent when entered at the command line:
= 10, 22
return 10, 22
print(10, 22)