Learning Lua
Introduction
This Repo's most content is taken from
Programming in Lua 4th Ed. by Roberto Lerusalimschy of Lua.Org
Get Lua
wget https://www.lua.org/ftp/lua-5.4.7.tar.gztar zxf lua-5.4.7.tar.gzcd lua-5.4.7make all install
$ lua -v Lua 5.4.7 Copyright (C) 1994-2024 Lua.org, PUC-RioStart Lua in interactive Mode like ipython or python by running
luaon command lineTo Exit Lua Interactive Mode use ctrl-D or os.exit()
To start an interactive session after running a lua script use eg.
lua -i basics-1.lua. Helpful for Debugging
Basics
Running Chunks
Each piece of code that Lua executes, such as a file or a single line in interactive mode, is called a chunk.
Run chunks by starting lua in interactive mode directly with
luaRun chunks by
dofile("<filename>")inside another lua script or in an interactive sessionRun chunks by adding
#!/usr/bin/env luaat the beginning of a lua script , the set executable bit for script viachmod +x basics-1.lua,and run it with name of script eg./basics-1.lua
Last updated