Use os.exit to immediately exit with a given status.
os.exit
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.
exit.lua
lua
$ lua exit.lua; echo $? 3
by Blake Bourque | source | license