These functions are defined in the global namespace. Alongside standard Lua functions, Space Lua provides the each and some convenience functions.
adder(a, b)
Adds two numbers.
Parameters:
a (number) — First number.b (number) — Second number.Returns:
number — sumassert(value, message?)
Raises an error when a value is falsy; otherwise completes successfully.
Parameters:
value — Condition to test.message? (string) — Error detail.Example:
assert(user ~= nil, "user is required")
See: API/global
clock()
dofile(path)
Reads and executes a Lua source file from the current space.
Parameters:
path (string) — Space-relative Lua file path.See: API/global
each(table)
Returns a Space Lua iterator over array-like values without yielding indices.
Parameters:
table (table)Returns:
function — Iterator yielding values.Example:
for fruit in each({"apple", "banana"}) do
print(fruit)
end
See: API/global
error(message)
Raises a Lua runtime error with the supplied message.
Parameters:
message (string)See: API/global
formatMarkdownTable(tree)
Parameters:
treegetmetatable(table)
Returns a table's metatable, or nil when none is set.
Parameters:
table (table)Returns:
table|nilSee: API/global
helloWorld(name)
Parameters:
nameipairs(table)
Returns an iterator over consecutive integer keys starting at 1 and stopping at the first nil.
Parameters:
table (table)Returns:
function — Iterator yielding index and value.Example:
for i, fruit in ipairs({"apple", "banana"}) do
print(i, fruit)
end
See: API/global
load(chunk)
Compiles Lua source into a callable chunk without executing it.
Parameters:
chunk (string) — Lua source code.Returns:
function|nil — Compiled chunk or nil.string — Compilation error when unsuccessful.See: API/global
marquee(text)
Parameters:
textnext(table, index?)
Returns the next table key and value after a given key, or the first pair when the key is omitted.
Parameters:
table (table)index? — Previous key.Returns:
nil.See: API/global
nodeParentOfType(tree, position, nodeType)
Parameters:
treepositionnodeTypepairs(table)
Returns an iterator over all table key-value pairs, respecting __pairs.
Parameters:
table (table)Returns:
function — Iterator plus its state and initial control value.Example:
for key, value in pairs({name = "Ada", age = 36}) do
print(key, value)
end
See: API/global
pcall(function, ...): boolean, ...
Calls a function in protected mode and returns a success flag followed by results or an error message.
Parameters:
function (function)... — Arguments passed to the function.Returns:
boolean — Whether the call succeeded.Example:
local ok, result = pcall(function() return mightFail() end)
See: API/global
print(...)
Prints string representations of its arguments to the runtime log.
Parameters:
... — Values to print.Example:
print("Hello, world!")
See: API/global
rawequal(a, b)
Tests two values for equality without invoking __eq.
Parameters:
abReturns:
booleanSee: API/global
rawget(table, key)
Reads a table key without invoking __index.
Parameters:
table (table)keyReturns:
nil.See: API/global
rawlen(value)
Returns a string or table length without invoking __len.
Parameters:
value (string|table)Returns:
integerSee: API/global
rawset(table, key, value)
Sets a table key without invoking __newindex and returns the table.
Parameters:
table (table)keyvalueReturns:
tableExample:
local t = setmetatable({}, {__newindex = function() error("blocked") end})
rawset(t, "name", "Ada")
See: API/global
select("#", ...): integer
select(index, ...): ...
Returns the count of extra arguments or all arguments from a selected position onward.
Parameters:
index (integer|string) — One-based index, negative index from the end, or #....Returns:
See: API/global
setmetatable(table, metatable)
Sets a table's metatable and returns the table.
Parameters:
table (table)metatable (table)Returns:
tableSee: API/global
some(value)
Returns nil for empty Space Lua values and otherwise returns the value unchanged.
Parameters:
value — Value to normalize; blank strings, empty tables, infinities, and NaN are empty.Returns:
nil.Example:
print(some(" ") or "empty")
print(some({}) or "empty")
print(some(0))
See: API/global
toggleReadOnlyMode()
tonumber(value): number|nil
tonumber(value, base): integer|nil
Converts a number or numeric string to a Lua number, optionally in a base from 2 through 36.
Parameters:
value (number|string)base? (integer)Returns:
number|nilExample:
print(tonumber("2a", 16)) -- 42
See: API/global
tostring(value)
Converts a value to a string, respecting its __tostring metamethod.
Parameters:
valueReturns:
stringSee: API/global
type(value)
Returns the Lua type name of a value.
Parameters:
valueReturns:
stringSee: API/global
xpcall(function, errorHandler, ...): boolean, ...
Calls a function in protected mode and transforms any error with an error handler.
Parameters:
function (function)errorHandler (function)... — Arguments passed to the function.Returns:
boolean — Whether the call succeeded.Example:
local ok, message = xpcall(riskyOperation, function(err)
return "Operation failed: " .. tostring(err)
end)
See: API/global