Lua by Example: Exit

Use os.exit to immediately exit with a given status.

Exit with status 3.

os.exit(3)

If you run exit.lua using lua, the exit code will be returned to the parent (the shell in this case). We can then print the exit code.

$ lua exit.lua; echo $?
3