LinuxCommandLibrary

lua

Execute Lua programs

TLDR

Start an interactive Lua shell

$ lua
copy

Execute a Lua script
$ lua [path/to/script.lua] [--optional-argument]
copy

Execute a Lua expression
$ lua -e '[print("Hello World")]'
copy

SYNOPSIS

lua [options] [script [args]]

PARAMETERS

-e stat
    Execute string 'stat'.

-i
    Enter interactive mode after executing 'script'.

-l name
    Require library 'name'.

-v
    Show version information.

--
    Stop handling options.

-
    Execute stdin as a file.

script
    The name of the Lua script file to execute.

args
    Arguments passed to the Lua script. These are accessible within the script through the arg table.

DESCRIPTION

The lua command is an interpreter that executes programs written in the Lua programming language. It allows users to run Lua scripts directly from the command line, making it a convenient tool for scripting, prototyping, and automation tasks. The interpreter loads and executes the Lua code provided as a file or directly through standard input. It supports standard Lua libraries, enabling users to interact with the operating system, manipulate strings, perform mathematical operations, and more.

The command provides access to the full power of the Lua scripting language, known for its simplicity, extensibility, and embeddability. It's widely used in game development, embedded systems, and web applications. The lua command facilitates rapid development cycles by enabling users to quickly test and execute Lua code without the need for a separate development environment. It's also useful for running Lua-based tools and applications.

CAVEATS

Ensure that the Lua script has execute permissions if running it directly with ./script.lua.

ERROR HANDLING

When an error occurs during the execution of a Lua script, the lua command typically prints an error message to the standard error stream (stderr) and exits. You can use pcall() within your scripts for more sophisticated error handling.

MODULES AND LIBRARIES

Lua utilizes modules and libraries extensively. The require function is crucial for loading external Lua modules. The LUA_PATH environment variable influences where Lua searches for these modules.

HISTORY

Lua was created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes at PUC-Rio (Pontifical Catholic University of Rio de Janeiro) in Brazil. It emerged as a scripting language for customizing and extending software applications. The lua command provides the primary means of executing Lua scripts from a Unix-like command line, allowing for its integration into system administration tasks, software builds, and general-purpose scripting.

SEE ALSO

luac(1)

Copied to clipboard