Try it in your browserpreview Source

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

Every require here was placed by hand; an undeclared module is an error, not a guess. See Modules and Lune's standard library.

Read a file

Open a file, and say how long it is.

Script Startfs.readFilefs.readFileResultREADME.mdpathLengthValueFormatREADME.m…FormatValuePrintValue
The graph this was compiled from, and what it declares.
luau
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.

Script Startnet.requestnet.requestResulthttps://…configGet KeyTablebodyKeyserde.decodeserde.decodeResultjsonformatencodedGet KeyTablestargaze…KeyFormatlune has…FormatValuePrintValue
The graph this was compiled from, and what it declares.
luau
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

The wire reading the body warns, and still compiles and runs. Roswaal knows Lune's type names but not their shapes, so it cannot tell 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.

Script Startfs.readDirfs.readDirResult.pathFor Each (Array)BodyCompletedArrayIndexValuefs.isDirfs.isDirResultpathBranchTrueFalseConditionConcatenate−+dir ABPrintValueConcatenate−+file ABPrintValue
The graph this was compiled from, and what it declares.
luau
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

The Branch's two arms sit on their own rows, so which Print belongs to True is plain.

A small command line

Take an argument, and say what to do when it is missing.

Script StartLuau Expressionprocess.argsCodeTable LengthTable0==BranchTrueFalseConditionPrintusage: l…Valueprocess.exitprocess.exitResult1×codeGet IndexTable1IndexConcatenate−+Hello, ABPrintValue
The graph this was compiled from, and what it declares.
luau
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

These are starting points. None checks whether the file exists, the request succeeded or the JSON has the field — a real version would.

Not reviewed yet