User Tools

Site Tools


programming:lua

Lua Programming Language

Lua is a scripting language that is commonly embedded within other applications. It is very portable. You can learn to program Lua with the free ebook on the official website, Programming in Lua, 1st Edition.

Installing

In Debian you can simply use the package manager:

sudo apt install lua5.3

Also search for other packages with apt-cache search lua because there are a lot of libraries available like http, json, filesystem, curl, curses, databases and more.

If you want to build from source, it's very easy because it's so portable and written in ANSI C. Simply download, extract and run make.

wget http://www.lua.org/ftp/lua-5.4.3.tar.gz
tar zxf lua-5.4.3.tar.gz
cd lua-5.4.3
make  # sudo apt install build-essential
src/lua -v
src/luac -v
sudo make install  # Optional

Executing code

There are a few ways you could execute a script:

  • In the interactive REPL: lua
  • By invoking the Lua interpreter and passing it a file: lua hello.lua
  • By executing a script directly with a shebang (e.g. #!/usr/bin/lua) and run with ./hello
  • Running a precompiled script. Compile with luac hello.lua and run with lua luac.out

Hello World

hello_world.lua
print 'hello world'
programming/lua.txt · Last modified: 2021/04/14 02:44 by nanodano