Lua does not work on the commandline

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Apr 13, 2010
The Hague
From the help:
lua -e'a=1' -e 'print(a)' script.lua
"... does not compute."
from an old sf movie.:smile:

But seriously, I can't get the simplest of snippets to work from the command line or @Lua[]

Running a file does seem to work, but anything quoted is ... unwieldy.

>lua -e print("Hello world")

surprisingly also works, although I would think the quoting is wrong.

So, would you be so kind to explain how I'm supposed to quote a Lua line like;

print(string.gsub("hello world", "(%w+)", "%1 %1"))
Dirk Jan Spits.
Comparison of internal Lua and two external versions I compiled myself.

TCC  20.00.22 x64   Windows 7 [Version 6.1.7601]

PROMPT> which lua & lua -v
lua is an internal command
Lua 5.3.3  Copyright (C) 1994-2016, PUC-Rio

PROMPT> which lua52 & lua52 -v
lua52 is an external : C:\BIN\lua52.exe
Lua 5.2.3  Copyright (C) 1994-2013, PUC-Rio

PROMPT> which lua53 & lua53 -v
lua53 is an external : C:\BIN\lua53.exe
Lua 5.3.3  Copyright (C) 1994-2016, PUC-Rio

PROMPT> lua -e "print(math.sin(12))"
Lua: (command line):1: unexpected symbol near '"print(math.sin(12))"'

PROMPT> lua52 -e "print(math.sin(12))"

PROMPT> lua53 -e "print(math.sin(12))"

PROMPT> lua -e "print('this is a test')"
Lua: (command line):1: unexpected symbol near '"print('this is a test')"'

PROMPT> lua52 -e "print('this is a test')"
this is a test

PROMPT> lua53 -e "print('this is a test')"
this is a test

Edit: Lua function seems to work...
PROMPT> %@lua[print(math.sin(12))]

PROMPT> %@lua[print('this is a test')]
this is a test
Last edited:
Apparently "-e" must not be followed by a space.
v:\> lua -e "print(math.sin(12))"
Lua: (command line):1: unexpected symbol near '"print(math.sin(12))"'

v:\> lua -e"print(math.sin(12))"
Apr 13, 2010
The Hague
Thanks guys. You inspired me to struggle on. Here's what I came up with:
C:\...\prj :-) >lua -e"print(string.gsub('hello world', '(%%w+)', '%%1 %%1'))"
hello hello world world 2
... which is the correct answer.

1) No space between -e and quotation mark
2) The outer character must be a double quote
3) Any quotes in the Lua string must then be a single quote
4) You must double any percent chars in the Lua strings

Point #3 means the TC user should be warned that most examples from the Lua manuals and tutorials will not run as-is and need to be adapted.

Or so I thought ... I decided to check my findings by changing the example in the TC help according to the rules above.

C:\...\prj :-( >lua -e'a=1' -e 'print(a)'
Lua: (command line):1: unfinished string near <eof>

C:\...\prj :-( >lua -e"a=1" -e"print(a)"
Lua: (command line):1: unexpected symbol near '"print(a)"'
I think I will wait until Rex relieves us from our suffering.
Last edited:
Just to make it more interesting. :-)
v:\> lua -e"a=1" -eprint(a)
Another problem is (I think, maybe already realized) that TCC's all-purpose parser considers '=' as an argument separator. I think that, because of that, the unfinished string in djspits's recent example (the one that failed) is
... that TCC skipped the '=' and started a new argument.[/code]


Staff member
May 14, 2008
First, you shouldn't be using the LUA command if you just want to execute a LUA argument; that's for @LUA[...].

The LUA command expects a script name, so it's looking for quotes and then removing them before passing the command line on to the LUA parser.

But if you really want to use LUA instead of @LUA, the = is a command delimiter in TCC, so you need to prevent that from being parsed. You need to set CMDBatchDelimiters=NO in your TCMD.INI.