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