1
votes

I have a Lua program in a file:

$ cat three.lua
for i = 1, 3 do print(i) end

It runs great with Lua 5.3:

$ lua three.lua
1
2
3

But I cannot run it on the command line with -e:

$ lua -e 'for i = 1, 3 do print(i) end'
lua5.3: (command line):1: <name> expected near <eof>

Simpler programs work fine with -e:

$ lua -e 'print("Hello");print("World")'
Hello
World

It seems Lua's script building -e does not like the structured for statement with the terminating end. What am I doing wrong?

1
For Linux, it works the way you have it. For Windows, you need double quotes. - tonypdmtr
Thanks. I'm on macOS and have installed Lua 5.3. from homebrew. Unfortunately double quotes do not work either. This script used to work with Lua 5.2. I might have a bad installation, or something changed in 5.3. - Ray Toal
Figured it out. Homebrew changed so that brew install lua does NOT install Lua 5.3! ARRRRRGGGHHH. So you have to brew install lua5.3, which makes an executable called lua5.3 (NOT lua!!!). Because I found this awful, I made my own lua script that invokes lua5.3. But I made it wrong. I made it say lua5.3 $@ instead of lua5.3 "$@". So it was not Lua's fault, but mine. I'm still very disappointed with the maintainers of Lua homebrew formula, but I'm sure they had their reasons, which were more important than my own desires. - Ray Toal

1 Answers

0
votes

This works as expected on macOS using Lua 5.3.4.