Assert a condition in Lua with assert. Check types, validate function returns, and when not to use assert for user-facing errors.
Reference
Core Functions
Built-in functions available in every Lua program.
- assert
- error
Raise a runtime error in Lua. Stop execution, propagate errors up the call stack, and use the level parameter to blame the right caller.
- ipairs
Iterate over sequential Lua tables with ipairs. This iterator traverses array-style entries in order, stopping at the first nil gap.
- next
Traverse Lua tables in arbitrary order with next(). Returns the next key-value pair or nil when the table is empty.
- pairs
Iterate over key-value pairs in Lua tables with pairs. Unlike ipairs, pairs iterates all entries including non-sequential keys and handles nil values correctly.
- pcall
Call a function in protected mode. If the function raises an error, pcall catches it and returns false with the error message instead of propagating the error.
- print()
Output one or more values to the console. print is the simplest way to inspect values during development and debugging in Lua.
- rawequal
Test whether two values are identical without invoking the __eq metamethod.
- rawget
Get a table value directly without invoking __index metamethod.
- rawlen
Get table or string length without calling the __len metamethod.
- rawset
Set a table value directly without invoking the __newindex metamethod.
- select
Select elements from a variadic argument list. Get all arguments after a position, or count the total arguments with the '#' selector.
- setmetatable
Assign a metatable to a table, enabling custom behavior for operators, indexing, and function calls.
- tonumber
Convert a string or number to a number in Lua. Parses integers with bases 2-36.
- tostring
Convert any Lua value to its string representation for debugging, logging, and concatenation.
- type()
Return the type name of any value as a string. Use type() to check what kind of value you're working with at runtime.
- xpcall
Call a function with a custom error handler. Like pcall but gives you the raw error message instead of a string. Useful for logging, debugging, and building...