LuaRocks and Popular Libraries
38.1 LuaRocks
luarocks install luasocket # global install (may need sudo)
luarocks install --local penlight # user install (~/.luarocks)
eval "$(luarocks path)" # set LUA_PATH/LUA_CPATH for local rocks
luarocks list
luarocks search json
luarocks remove luasocket
luarocks --lua-version=5.1 install lpeg # target a specific Lua version
luarocks init # project-local tree (./lua_modules) + ./lua wrapper
luarocks make # build from a rockspec in the current directory
luarocks upload mylib-1.0-1.rockspec --api-key=...-- mylib-1.0-1.rockspec
package = "mylib"
version = "1.0-1"
source = { url = "git+https://github.com/me/mylib.git", tag = "v1.0" }
description = { summary = "My library", license = "MIT" }
dependencies = { "lua >= 5.1", "penlight >= 1.13" }
build = {
type = "builtin",
modules = {
["mylib"] = "src/mylib.lua",
["mylib.core"] = "src/mylib/core.lua",
["mylib.native"] = { sources = { "src/native.c" } },
},
}38.2 Essential Libraries
Penlight (pl.*: lists, strings, paths, classes, pretty printing), lume, moses (functional), inspect.lua (pretty print tables)
lua-cjson (fast C), dkjson (pure Lua), rxi/json.lua, lunajson
lyaml, lua-toml, xml2lua, lua-MessagePack, ftcsv (CSV)
LuaFileSystem (lfs), luaposix, luv (libuv bindings)
LuaSocket, LuaSec (TLS), lua-http, copas, luv
LPeg, lrexlib (PCRE/POSIX regex) LuaSQL (MySQL, PostgreSQL, SQLite), lsqlite3, pgmoon (OpenResty), lua-resty-redis
luaossl, lua-resty-string, md5.lua, luatweetnacl
argparse, lua-term, ansicolors luatz, date (Tieske/date) busted, luaunit, luacov, luacheck, LDoc
Lanes (multi-threading with separate states), effil, copas, cqueues
local json = require("dkjson") -- or require("cjson")
local str = json.encode({name = "Ana", tags = {"lua", "c"}, active = true}, {indent = true})
local obj, pos, err = json.decode('{"x": 1, "list": [1, 2, 3]}')
print(obj.x, #obj.list)
local inspect = require("inspect")
print(inspect({a = {b = {c = 1}}, 1, 2}))
local lfs = require("lfs")
for entry in lfs.dir(".") do
if entry ~= "." and entry ~= ".." then
local attr = lfs.attributes(entry)
print(entry, attr.mode, attr.size)
end
end
lfs.mkdir("output")