Running scripts and the REPL
Run a file with the lua command, or type lines one by one in the interactive prompt.
In this page:
Running scripts and the REPL
Running lua with no arguments starts the interactive REPL, where each line is executed immediately. Running lua script.lua executes a file, and extra command-line words become the global table arg. The option -e runs a snippet directly, and -i drops into the REPL after a script.
Note:
In the REPL of Lua 5.3 you can type =expression to print its value.
Example: Running scripts and the REPL
$ lua
Lua 5.3.6 Copyright (C) 1994-2020 Lua.org, PUC-Rio
> x = 10
> =x * 2
20
> os.exit()
$ lua hello.lua alpha beta
$ lua -e "print('hi')"
hi
⚠️ Run this in your own terminal or Node.js environment.
Common Mistakes
- Typing lua without a file and expecting nothing to happen
- Forgetting the .lua extension in the file name
- Expecting arg to exist inside the REPL
Chapter Summary
- lua alone opens the REPL
- lua file.lua runs a script
- arg holds command-line arguments
- lua -e runs a string of code
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: