Skip to content

Standard Lua Libraries

Core Lua libraries automatically available in all Wippy processes. No require() needed.

type(value) -- Returns: "nil", "number", "string", "boolean", "table", "function", "thread", "userdata"
tonumber(s [,base]) -- Convert to number, optional base (2-36)
tostring(value) -- Convert to string, calls __tostring metamethod
assert(v [,msg]) -- Raises error if v is false/nil, returns v otherwise
error(msg [,level]) -- Raises error at specified stack level (default 1)
pcall(fn, ...) -- Protected call, returns ok, result_or_error
xpcall(fn, errh) -- Protected call with error handler function
pairs(t) -- Iterate all key-value pairs
ipairs(t) -- Iterate array portion (1, 2, 3, ...)
next(t [,index]) -- Get next key-value pair after index
getmetatable(obj) -- Get metatable (or __metatable field if protected)
setmetatable(t, mt) -- Set metatable, returns t

Bypass metamethods for direct table access:

rawget(t, k) -- Get t[k] without __index
rawset(t, k, v) -- Set t[k]=v without __newindex
rawequal(a, b) -- Compare without __eq
select(index, ...) -- Return args from index onwards
select("#", ...) -- Return number of args
unpack(t [,i [,j]]) -- Return t[i] through t[j] as multiple values
print(...) -- Print values (uses structured logging in Wippy)
_G -- The global environment table
_VERSION -- Lua version string

Functions for modifying tables:

table.insert(t, [pos,] value) -- Insert value at pos (default: end)
table.remove(t [,pos]) -- Remove and return element at pos (default: last)
table.concat(t [,sep [,i [,j]]]) -- Concatenate array elements with separator
table.sort(t [,comp]) -- Sort in place, comp(a,b) returns true if a < b
table.unpack(t [,i [,j]]) -- Unpack table elements as multiple values
local items = {"a", "b", "c"}
table.insert(items, "d") -- {"a", "b", "c", "d"}
table.insert(items, 2, "x") -- {"a", "x", "b", "c", "d"}
table.remove(items, 2) -- {"a", "b", "c", "d"}, returns "x"
local csv = table.concat(items, ",") -- "a,b,c,d"
table.sort(items, function(a, b)
return a > b -- Descending order
end)

String manipulation functions. Also available as methods on string values:

string.find(s, pattern [,init [,plain]]) -- Find pattern, returns start, end, captures
string.match(s, pattern [,init]) -- Extract matching substring
string.gmatch(s, pattern) -- Iterator over all matches
string.gsub(s, pattern, repl [,n]) -- Replace matches, returns string, count
string.upper(s) -- Convert to uppercase
string.lower(s) -- Convert to lowercase
string.sub(s, i [,j]) -- Substring from i to j (negative indexes from end)
string.len(s) -- String length (or use #s)
string.byte(s [,i [,j]]) -- Numeric codes of characters
string.char(...) -- Create string from character codes
string.rep(s, n) -- Repeat string n times
string.reverse(s) -- Reverse string
string.format(fmt, ...) -- Printf-style formatting

Format specifiers: %d (integer), %f (float), %s (string), %q (quoted), %x (hex), %o (octal), %e (scientific), %% (literal %)

local s = "Hello, World!"
-- Pattern matching
local start, stop = string.find(s, "World") -- 8, 12
local word = string.match(s, "%w+") -- "Hello"
-- Substitution
local new = string.gsub(s, "World", "Wippy") -- "Hello, Wippy!"
-- Method syntax
local upper = s:upper() -- "HELLO, WORLD!"
local part = s:sub(1, 5) -- "Hello"
PatternMatches
.Any character
%aLetters
%dDigits
%wAlphanumeric
%sWhitespace
%pPunctuation
%cControl characters
%xHexadecimal digits
%zZero (null)
[set]Character class
[^set]Negated class
*0 or more (greedy)
+1 or more (greedy)
-0 or more (lazy)
?0 or 1
^Start of string
$End of string
%b()Balanced pair
(...)Capture group

Uppercase versions (%A, %D, etc.) match the complement.

Mathematical functions and constants:

math.pi -- 3.14159...
math.huge -- Infinity
math.mininteger -- Minimum integer
math.maxinteger -- Maximum integer
math.abs(x) -- Absolute value
math.min(...) -- Minimum of arguments
math.max(...) -- Maximum of arguments
math.floor(x) -- Round down
math.ceil(x) -- Round up
math.modf(x) -- Integer and fractional parts
math.fmod(x, y) -- Floating-point remainder
math.sqrt(x) -- Square root
math.pow(x, y) -- x^y (or use x^y operator)
math.exp(x) -- e^x
math.log(x) -- Natural log
math.log10(x) -- Base-10 log
math.sin(x) math.cos(x) math.tan(x) -- Radians
math.asin(x) math.acos(x) math.atan(x)
math.atan2(y, x) -- Arc tangent of y/x
math.sinh(x) math.cosh(x) math.tanh(x) -- Hyperbolic
math.deg(r) -- Radians to degrees
math.rad(d) -- Degrees to radians
math.random() -- Random float [0,1)
math.random(n) -- Random integer [1,n]
math.random(m, n) -- Random integer [m,n]
math.randomseed(x) -- Set random seed
math.tointeger(x) -- Convert to integer or nil
math.type(x) -- "integer", "float", or nil
math.ult(m, n) -- Unsigned less-than comparison

Coroutine creation and control. See Channels and Coroutines for channels and concurrent patterns:

coroutine.create(fn) -- Create coroutine from function
coroutine.resume(co, ...) -- Start/continue coroutine
coroutine.yield(...) -- Suspend coroutine, return values to resume
coroutine.status(co) -- "running", "suspended", "normal", "dead"
coroutine.running() -- Current coroutine (nil if main thread)
coroutine.wrap(fn) -- Create coroutine as callable function

Spawn a concurrent coroutine that runs independently (Wippy-specific):

coroutine.spawn(fn) -- Spawn function as concurrent coroutine
-- Spawn background task
coroutine.spawn(function()
while true do
check_health()
time.sleep("30s")
end
end)
-- Continue main execution immediately
process_request()

Structured error creation and classification. See Error Handling for full documentation:

errors.UNKNOWN -- Unclassified error
errors.INVALID -- Invalid argument or input
errors.NOT_FOUND -- Resource not found
errors.ALREADY_EXISTS -- Resource already exists
errors.PERMISSION_DENIED -- Permission denied
errors.TIMEOUT -- Operation timed out
errors.CANCELED -- Operation cancelled
errors.UNAVAILABLE -- Service unavailable
errors.INTERNAL -- Internal error
errors.CONFLICT -- Conflict (e.g., concurrent modification)
errors.RATE_LIMITED -- Rate limit exceeded
-- Create error from string
local err = errors.new("something went wrong")
-- Create error with metadata
local err = errors.new({
message = "User not found",
kind = errors.NOT_FOUND,
retryable = false,
details = {user_id = 123}
})
-- Wrap existing error with context
local wrapped = errors.wrap(err, "failed to load profile")
-- Check error kind
if errors.is(err, errors.NOT_FOUND) then
-- handle not found
end
-- Get call stack from error
local stack = errors.call_stack(err)
err:message() -- Get error message string
err:kind() -- Get error kind (e.g., "NOT_FOUND")
err:retryable() -- true, false, or nil (unknown)
err:details() -- Get details table or nil
err:stack() -- Get stack trace as string

The following standard Lua features are NOT available for security:

FeatureAlternative
load, loadstring, loadfile, dofileUse Dynamic Evaluation module
collectgarbageAutomatic GC
rawlenUse # operator
io.*Use File System module
os.execute, os.exit, os.remove, os.rename, os.tmpnameUse Command Execution, Environment modules
debug.*Not available
utf8.*Not available
package.loadlibNative libraries not supported