Lua4Win

Lua4Win is a distribution the Lua programming language for Windows.

Download

Rational

Unlike alternative distributions, Lua4Win comes with the Luarocks package manager and is a "batteries-not-included" distribution of Lua. Binary packages are built in the cloud and can be downloaded as-needed. The Lua4Win installer contains a copy of LuaJIT, Luarocks, Busybox, and 7zip; which allows it to come in at a slim 2MB. Updates and bugfixes can be done piecemeal instead of requireing new copies of the whole distribution every time a bug gets fixed.

Usage

After installing, you can launch cmd.exe and run $ lua to get started.

$ lua
LuaJIT 2.0.ROLLING -- Copyright (C) 2005-2023 Mike Pall. https://luajit.org/
JIT: ON CMOV SSE2 SSE3 SSE4.1 AMD fold cse dce fwd dse narrow loop abc sink fuse
> print("Hello, world!")
Hello, world!
>

You can use CTRL+C to escape the read-evaluate-print-loop. You can also write Lua programs with your favorite text editor and run them with $ lua filename.lua

note.lua
-- Create a note file with today's date in %APPDATA%
local args = {...} -- extra arguments passed to the program
-- Generate a filename
local notes_folder = os.getenv("APPDATA")
local today = os.date("%Y-%m-%d")
local note_name = table.concat(args,"-"):gsub("[%W]","-")
local note_filename = string.format("%s\note-%s-%s.txt",notes_folder,today,note_name)
-- Create the file
local fd = assert(io.open(note_filename,"w"))
assert(fd:close())
-- Open it in notepad
os.execute("notepad.exe " .. note_filename)
$ lua note.lua my first note

Run lua --help for more options for the command line tool, and the Lua Manual for extensive documentation of the Lua programming language. Also note LuaJIT's extensions

Installing Superpowers

You can use modules that implement more than the standard lua libraries by running the $ luarocks install >module name< command to download and install modules.

color.lua
local eansi = require("eansi")
eansi.enable = true
print(eansi.toansi("green") .. "> implying you need modules" .. eansi(""))
$ luarocks install eansi

$ lua color.lua

Run luarocks --help for more options on the command line tool, and the Luarocks wiki for more extensive documentation.

Sister languages

Lua4Win makes it easy to download other programming languages that are distributed through the luarocks package manager. Simply luarocks install them like you would any other package.

Moonscript

example.moon
$ luarocks install moonscript
class World
  greet: => print("Hello, world!")

with World!
  \greet!
$ moonscript example.moon
Hello, world!

Teal

keys.tl
$ luarocks install tl
local function keys(xs: {K:V}):{K}
  local ks = {}
  for k, v in pairs(xs) do
    table.insert(ks, k)
  end
  return ks
end

local s: {number:string} = keys({ a = 1, b = 2 })
print(table.concat(s))
$ tl keys.tl
ab

Advanced Usage

Lua4Win allows you to install system-wide packages with the

--tree system
flag, these packages will be located at
[INSTALLDIR]/luarocks
. You may need to be running as an administratior to install to this location.

Lua4Win's luarocks config lives at

[INSTALLDIR]/config/config-5.1.lua

All of Lua4Win's binary packages are built using mingw64, if you intend to build your own modules, they must be built with mingw64 if you want them to operate with Lua4Win-distributed Lua.

Some of Lua4Win's packages needed patching or modification, source code is generally mirrored at git.lua4.win, and packaging code is kept seperate, usually in a repo

*-packaging