1.\" $Id: lua.man,v 1.14 2024/05/08 18:48:27 lhf Exp $
  2.TH LUA 1 "$Date: 2024/05/08 18:48:27 $"
  3.SH NAME
  4lua \- Lua interpreter
  5.SH SYNOPSIS
  6.B lua
  7[
  8.I options
  9]
 10[
 11.I script
 12[
 13.I args
 14]
 15]
 16.SH DESCRIPTION
 17.B lua
 18is the standalone Lua interpreter.
 19It loads and executes Lua programs,
 20either in textual source form or
 21in precompiled binary form.
 22(Precompiled binaries are output by
 23.BR luac ,
 24the Lua compiler.)
 25.B lua
 26can be used as a batch interpreter and also interactively.
 27.LP
 28After handling the
 29.IR options ,
 30the Lua program in file
 31.I script
 32is loaded and executed.
 33The
 34.I args
 35are available to
 36.I script
 37as strings in a global table named
 38.B arg
 39and also as arguments to its main function.
 40When called without arguments,
 41.B lua
 42behaves as
 43.B "lua \-v \-i"
 44if the standard input is a terminal,
 45and as
 46.B "lua \-"
 47otherwise.
 48.LP
 49In interactive mode,
 50.B lua
 51prompts the user,
 52reads lines from the standard input,
 53and executes them as they are read.
 54If the line contains an expression,
 55then the line is evaluated and the result is printed.
 56If a line does not contain a complete statement,
 57then a secondary prompt is displayed and
 58lines are read until a complete statement is formed or
 59a syntax error is found.
 60.LP
 61Before handling command line options and scripts,
 62.B lua
 63checks the contents of the environment variables
 64.B LUA_INIT_5_4
 65and
 66.BR LUA_INIT ,
 67in that order.
 68If the contents are of the form
 69.RI '@ filename ',
 70then
 71.I filename
 72is executed.
 73Otherwise, the contents are assumed to be a Lua statement and is executed.
 74When
 75.B LUA_INIT_5_4
 76is defined,
 77.B LUA_INIT
 78is ignored.
 79.SH OPTIONS
 80.TP
 81.BI \-e " stat"
 82execute statement
 83.IR stat .
 84.TP
 85.B \-i
 86enter interactive mode after executing
 87.IR script .
 88.TP
 89.BI \-l " mod"
 90require library
 91.I mod
 92into global
 93.IR mod .
 94.TP
 95.BI \-l " g=mod"
 96require library
 97.I mod
 98into global
 99.IR g .
100.TP
101.B \-v
102show version information.
103.TP
104.B \-E
105ignore environment variables.
106.TP
107.B \-W
108turn warnings on.
109.TP
110.B \-\-
111stop handling options.
112.TP
113.B \-
114stop handling options and execute the standard input as a file.
115.SH ENVIRONMENT VARIABLES
116The following environment variables affect the execution of
117.BR lua .
118When defined,
119the version-specific variants take priority
120and the version-neutral variants are ignored.
121.TP
122.B LUA_INIT, LUA_INIT_5_4
123Code to be executed before command line options and scripts.
124.TP
125.B LUA_PATH, LUA_PATH_5_4
126Initial value of package.path,
127the path used by require to search for Lua loaders.
128.TP
129.B LUA_CPATH, LUA_CPATH_5_4
130Initial value of package.cpath,
131the path used by require to search for C loaders.
132.SH EXIT STATUS
133If a script calls os.exit,
134then
135.B lua
136exits with the given exit status.
137Otherwise,
138.B lua
139exits
140with EXIT_SUCCESS (0 on POSIX systems) if there were no errors
141and
142with EXIT_FAILURE (1 on POSIX systems) if there were errors.
143Errors raised in interactive mode do not cause exits.
144.SH DIAGNOSTICS
145Error messages should be self explanatory.
146.SH "SEE ALSO"
147.BR luac (1)
148.br
149The documentation at lua.org,
150especially section 7 of the reference manual.
151.SH AUTHORS
152R. Ierusalimschy,
153L. H. de Figueiredo,
154W. Celes
155.\" EOF