Lua does not work on the commandline

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.
Jan 19, 2011
Norman, OK
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:
May 20, 2008
Syracuse, NY, USA
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:
May 20, 2008
Syracuse, NY, USA
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.
Similar threads
Thread starter Title Forum Replies Date
D Fixed @Lua does not behave as documented Support 8
T Take Command 28: Lua reports version 5.4.0 (5.4.3 expected) [SOLVED] Support 1
fpefpe Documentation LUA and friends Support 4
T Returning a value from internal Lua scripts to TCC Support 2
H Lua and lpeg Support 1
fpefpe How to? LUA script Support 0
fpefpe How to? Lua Examples Support 1
H lua Causes Take Command Tab to Exit Support 5
jbarnes1967 TC 18.00 x64 issue with lua io.popen() Support 2
M How to make Lua modify env-vars Support 18
Joe Caverly Internal Lua and require Support 0
jbanaszczyk LUA, tcmd.chm, TCC/LE problem Support 0
Jay Sage Executable Extension with Lua Support 5
tmaynard Invalid item name "Lua" Support 6
vefatica Help LUA Support 1
T Lua sharing data with batch files Support 2
JohnQSmith Documentation Lua Support 0
p.f.moore Lua for Take Command, release 1.0 Support 0
T Plugins for Lua and Idle Support 4
T Fixed Function @timer[] does not work as required Support 6
D Parsing an array variable to an array does not work Support 5
J Take command does not start on Windows 10 Support 3
J ffind does not find files Support 4
Joe Caverly PAUSE does not erase countdown timer Support 0
D ParentDirectory does not update directory history Support 6
D Documentation Help "Startup" page does not describe global lists Support 0
Charles Dye Does HASH's /E option do anything? Support 1 First TCC instantiation after reboot does not work. Support 17
D Fixed @VERSION does not increment pre-fixed version numbers. Support 1
vefatica Why does @WSLPATH double the leading '/'? Support 7
D What does the file "..\Everything\Run history.csv" store? Support 5
Peter Murschall WAD rem does not work correctly Support 8
vefatica Does @SYMLINK work? Support 6
R Tree on FAT32 does not sort by name by default. Support 6
A Tcc does not recognize "bcdedit" Support 20
MickeyF Why does this batch file give me 'unknown command "else"' error? Support 17
M Ctrl-C when using command line history does nothing Support 2
vefatica JOBS /K ... how does it work? Support 5
Joe Caverly Why does TCCRT return VIEW as an internal command? Support 6
D Does TCC improve CMD's implementation of ECHO? Support 6
vefatica Find Files/Text dialog: does it work? Support 0
Alpengreis [v22.00.41] sync command flag "/X" does not work Support 22
Joe Caverly .PS1 script does not work with PSHELL Support 11
M MOVE does not behaves like intended (on failure) Support 1
R Fixed Sendmail parameter /USER= does not work Support 4
twaterloo does tcc have a task sceduler Support 4
Brian Woodward How to? Does FTP.CFG only support SSL over port 21? (Newbie) Support 6
M Activation Key does not correspond… Support 2
James Miller tcc shell window does not disappear Support 18
D Fresh instance of TCMD does not use TCMD.INI Support 7

Similar threads