LUA5.4(1)

πŸ“¦
version 5.4.9 Β· 4 versions
, in debian trixie, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– lua β€” the Lua interpreter, bestie edition πŸ’–

okay so real talk: this is the manual page for lua, the standalone Lua interpreter, living in the LUA5.4(1) era of the General Commands Manual. yes it's a manpage. no it doesn't have to be boring. let's go πŸ¦‹


✨ SYNOPSIS ✨

lua [ options ] [ script [ args ] ]

that's it. that's the whole vibe. options, then optionally a script, then optionally some args for that script. periodt. πŸ’…


🌸 DESCRIPTION 🌸

lua is the standalone Lua interpreter. it loads and executes Lua programs β€” either in textual source form or in precompiled binary form. (the precompiled binaries? those come out of luac, the Lua compiler. so luac makes them, lua runs them. iconic duo fr fr.) and lua can be used as a batch interpreter and interactively. versatile queen. πŸ‘‘

So here's the flow: after handling the options, the Lua program in file script gets loaded and executed. the args are available to script as strings in a global table named arg β€” and also as arguments to its main function. two ways in, both valid, we love options.

When you call lua with no arguments at all:

  • if the standard input is a terminal, it behaves as lua -v -i
  • otherwise, it behaves as lua -

In interactive mode, lua prompts the user, reads lines from the standard input, and executes them as they are read. if the line contains an expression, then the line is evaluated and the result is printed. if a line doesn't contain a complete statement, then a secondary prompt shows up and lines are read until a complete statement is formed β€” or until a syntax error is found. 😭

Important pre-game ritual: before handling command line options and scripts, lua checks the contents of the environment variables LUA_INIT_5_4 and LUA_INIT, in that order. if the contents are of the form '@filename', then filename is executed. otherwise, the contents are assumed to be a Lua statement and get executed. and when LUA_INIT_5_4 is defined, LUA_INIT is ignored. no cap.


πŸŽ€ OPTIONS πŸŽ€

  • -e stat β€” execute statement stat. just do it. right there. immediately. ⭐
  • -i β€” enter interactive mode after executing script. main character energy, but make it a sequel.
  • -l mod β€” require library mod into global mod. so it lands in a global with the same name. neat.
  • -l g=mod β€” require library mod into global g. now you get to pick the name yourself, custom queen. πŸ’…
  • -v β€” show version information. who am I? what am I? valid questions.
  • -E β€” ignore environment variables. going no-contact with the env, we respect it. πŸ™ˆ
  • -W β€” turn warnings on. the gentle callouts begin. 🫢
  • -- β€” stop handling options. everything after is not an option, bestie.
  • - β€” stop handling options and execute the standard input as a file. two jobs, one tiny dash. 🌈

πŸ¦‹ ENVIRONMENT VARIABLES πŸ¦‹

The following environment variables affect the execution of lua. and here's the rule: when defined, the version-specific variants take priority and the version-neutral variants are ignored. so like, pick a lane, versions. 😌

  • LUA_INIT, LUA_INIT_5_4 β€” code to be executed before command line options and scripts. the warm-up. the pre-roll. πŸ”₯
  • LUA_PATH, LUA_PATH_5_4 β€” initial value of package.path, the path used by require to search for Lua loaders. this is where your Lua modules get hunted down. πŸ”
  • LUA_CPATH, LUA_CPATH_5_4 β€” initial value of package.cpath, the path used by require to search for C loaders. same energy, but for the C side. ✨

πŸ’€ EXIT STATUS πŸ’€

If a script calls os.exit, then lua exits with the given exit status. otherwise:

  • exits with EXIT_SUCCESS (0 on POSIX systems) if there were no errors
  • exits with EXIT_FAILURE (1 on POSIX systems) if there were errors
and one lil caveat that matters: errors raised in interactive mode do not cause exits. the REPL forgives. the REPL forgets. πŸ’–

πŸ” DIAGNOSTICS πŸ”

Error messages should be self explanatory. that's the whole section. the errors explain themselves. self-sufficient. independent. we stan a self-explanatory error. 😭


🌟 SEE ALSO 🌟

  • luac(1)
  • The documentation at lua.org β€” especially section 7 of the reference manual. iykyk. πŸ“š

πŸ‘‘ AUTHORS πŸ‘‘

R. Ierusalimschy, L. H. de Figueiredo, W. Celes


and that's the page, bestie!! πŸŽ€ this was LUA5.4(1) from the General Commands Manual, stamped $Date: 2024/05/08 18:48:27 $, and honestly? iconic. go run some Lua. slay. πŸ’œπŸ¦‹βœ¨