Lune demos✎
Four small programmes: read a file, fetch JSON, walk a directory, take an argument.
Pending review
Four programmes somebody writes first, each one a graph and the file it compiles to. They are small on purpose: the point is the shape, and the shortest version of a shape is the one you can take away.
Info
Read a file
Open a file, and say how long it is.
local fs = require("@lune/fs") print(string.format("README.md is %d characters.", #fs.readFile("README.md")))
Info
fs.readFile is a value node — no execution pins — because Lune tags it must_use.Fetch JSON and read a field
Ask an HTTP API for something, and pull one value out of the answer.
local net = require("@lune/net") local serde = require("@lune/serde") local result = net.request("https://api.github.com/repos/lune-org/lune") print(string.format("lune has %d stars.", serde.decode("json", result.body).stargazers_count))
Info
net.request is a step and serde.decode a value, by the same rule. Both modules are declared here by hand.Warning
FetchResponse is a table. fs.metadata does the same.Walk a directory
List what is in a folder, and say which entries are folders themselves.
local fs = require("@lune/fs") for i, value in ipairs(fs.readDir(".")) do if fs.isDir(value) then print("dir " .. value) else print("file " .. value) end end
Info
A small command line
Take an argument, and say what to do when it is missing.
local process = require("@lune/process") if #process.args == 0 then print("usage: lune run greet -- <name>") process.exit(1) else print("Hello, " .. process.args[1]) end
Info
process.args is a property, not a function, so it has no node; a Luau Expression reads it through the module's local.Running one
Compile the graph, then run the file — lune run count-characters. Roswaal writes the .luau and stops there; what runs it is Lune. Where the file lands, and what checks that the layout holds together, is on Compiling and nodemaps for Lune.
Warning
Not reviewed yet