Space Lua includes a comprehensive standard library based on Lua 5.4, with additional non-standard extensions useful for text processing and note-taking workflows.
This page gives an overview. Each module has its own detailed API reference page.
The following functions are available globally (no module prefix needed):
print(...): Print to the log (browser console or server log)type(v): Returns the type of a value as a stringtostring(v): Converts a value to its string representationtonumber(s): Converts a string to a numberassert(expr, msg?): Raises an error if expr is falsyerror(msg): Throws an errorpcall(fn, ...): Calls a function in protected mode, catching errorsxpcall(fn, handler): Like pcall but with a custom error handlerpairs(t): Iterator over all key-value pairs in a tableipairs(t): Iterator over integer-keyed entries in orderunpack(t): Unpacks a table into individual valuessetmetatable(t, mt): Sets the metatable for a tablegetmetatable(t): Gets the metatable of a tablerawset(t, k, v): Sets a table key bypassing metamethodsdofile(path): Loads and executes a .lua file from your spaceNon-standard globals:
each(t): Iterator over values only (no indices)some(v): Returns nil if value is “empty” (empty table, whitespace-only string, inf, nan), otherwise returns the value unchangedsome() is particularly useful in templates and queries for handling missing data gracefully:
print(some("hello")) -- hello
print(some("")) -- nil
print(some({})) -- nil
print(some({}) or "empty") -- empty
Full reference: API/global
Standard Lua string operations plus useful extensions. Since strings have string as their metatable, you can call these as methods: s:startsWith("h").
Non-standard extensions:
string.split(s, sep): Splits a string by separatorstring.startsWith(s, prefix): Tests if a string starts with a prefixstring.endsWith(s, suffix): Tests if a string ends with a suffixstring.trim(s): Strips whitespace from both endsstring.trimStart(s): Strips leading whitespacestring.trimEnd(s): Strips trailing whitespacestring.matchRegex(s, pattern): Matches against a JavaScript regexstring.matchRegexAll(s, pattern): Iterator over all JavaScript regex matcheswarning Lua patterns vs. regex Standard Lua
string.find,string.match,string.gmatch, andstring.gsubuse Lua patterns, which are not regular expressions. See API/string for differences. UsematchRegex/matchRegexAllwhen you need full regex support.
Full reference: API/string
Table manipulation functions, plus non-standard extensions:
table.keys(t): Returns an array of all keystable.includes(t, value): Checks if a list contains a valuetable.find(t, fn, from?): Finds first element matching a criteria functiontable.select(t, keys...): Returns a new table with only selected keysFull reference: API/table
Standard Lua math functions (abs, ceil, floor, max, min, sqrt, sin, cos, trigonometric functions, etc.) plus:
math.cosineSimilarity(a, b): Cosine similarity between two vectorsFull reference: API/math
Date and time functions:
os.time(table?): Current Unix timestamp, or timestamp for a specific dateos.date(format?, timestamp?): Formats a timestamp as a stringFull reference: API/os
Functions for encoding and decoding data:
encoding.base64Encode(data): Encode data as base64encoding.base64Decode(s): Decode a base64 stringencoding.utf8Encode(s): Encode a UTF-8 string to bytesencoding.utf8Decode(data): Decode bytes to a UTF-8 stringFull reference: API/encoding
See also: Reference/Space Lua, Space Lua/JavaScript Interop