Lua LuaRocks Notes
A rockspec is a Lua table that describes one package for LuaRocks. It lists the package name, version, source, and dependencies.
A rockspec names the package and version
The first two fields identify the package. Reading them shows exactly which release is described.
local spec = { package = "greet", version = "1.0.0", source = { url = "https://example.com/greet-1.0.0.tar.gz" }, dependencies = { "lua >= 5.4" } }
print(spec.package, spec.version)The source field gives the origin
The source table holds the origin address. Reading its url field shows where the package comes from.
local spec = { package = "greet", version = "1.0.0", source = { url = "https://example.com/greet-1.0.0.tar.gz" }, dependencies = { "lua >= 5.4" } }
print(spec.source.url)Dependencies are a list
Each entry names one package the package needs. The list length shows how many there are.
local spec = { package = "greet", version = "1.0.0", source = { url = "https://example.com/greet-1.0.0.tar.gz" }, dependencies = { "lua >= 5.4" } }
print(#spec.dependencies, spec.dependencies[1])Example
local spec = { package = "notes", version = "0.9.0", source = { url = "https://example.com/notes-0.9.0.tar.gz" }, dependencies = { "lua >= 5.4", "lpeg >= 1.0" } }
print(spec.package)
print(spec.version)
print(#spec.dependencies .. " dependencies")
print(spec.dependencies[1])Key points
- Package: the package field names the package.
- Version: the version field names the release.
- Source: the source field says where the package comes from.
- Dependencies: the dependencies field lists other packages it needs.
- Table form: a rockspec is plain data, not code that runs the package.
In this example, a literal rockspec table is read field by field. The package and version print first. Then the dependency count prints, followed by the first dependency.
Note
this lesson reads a literal table only, with no download.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which rockspec field lists the other packages a package needs?