Lua: Running Code & Tools
Running Lua
lua script.lua # run a script
lua -i script.lua # run the script, then enter interactive mode
lua -e "print(1 + 1)" # run inline code
luajit script.lua # run with LuaJIT (a fast JIT compiler)
Major use cases
Lua is not typically used for standalone applications — it's designed as an embeddable language:
| Domain | Example |
|---|---|
| Game scripting | Roblox (Luau), World of Warcraft, Love2D framework |
| Embedded systems | Redis (scripting), Nginx (OpenResty), Wireshark |
| Configuration | Neovim, Awesome WM, Hammerspoon |
| Desktop apps | Aegisub (subtitles), VLC |
Editors
- VS Code — install the Lua extension by sumneko (lua-language-server) for autocomplete, diagnostics, and type checking
- ZeroBrane Studio — lightweight IDE specifically designed for Lua development
- Vim/Neovim with lua-language-server LSP for code intelligence
- Roblox Studio — built-in script editor for Roblox's Luau dialect
LuaRocks (package manager)
luarocks install luasocket # install a rock (package)
luarocks list # list installed rocks
luarocks search lua # search for packages
luarocks remove luasocket # uninstall
Luau (Roblox Lua)
Roblox uses Luau, a derivative of Lua 5.1 with:
- Type annotations (gradual typing)
- Performance optimizations for game scripting
- continue keyword (not in standard Lua)
- Bitwise operators as built-in
Getting started with Love2D
Love2D is a framework for making 2D games in Lua:
# Create main.lua:
# function love.draw() love.graphics.print("Hello", 400, 300) end
love . # run the game
Common resources
- Programming in Lua — the official book (first edition free online)
- Lua 5.4 Reference Manual — authoritative documentation
- luarocks.org — LuaRocks package registry
Quick check below!