luaguides

Reference

Core Functions

Built-in functions available in every Lua program.

  1. assert

    Assert a condition in Lua with assert. Check types, validate function returns, and when not to use assert for user-facing errors.

  2. 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.

  3. ipairs

    Iterate over sequential Lua tables with ipairs. This iterator traverses array-style entries in order, stopping at the first nil gap.

  4. next

    Traverse Lua tables in arbitrary order with next(). Returns the next key-value pair or nil when the table is empty.

  5. 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.

  6. 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.

  7. print()

    Output one or more values to the console. print is the simplest way to inspect values during development and debugging in Lua.

  8. rawequal

    Test whether two values are identical without invoking the __eq metamethod.

  9. rawget

    Get a table value directly without invoking __index metamethod.

  10. rawlen

    Get table or string length without calling the __len metamethod.

  11. rawset

    Set a table value directly without invoking the __newindex metamethod.

  12. select

    Select elements from a variadic argument list. Get all arguments after a position, or count the total arguments with the '#' selector.

  13. setmetatable

    Assign a metatable to a table, enabling custom behavior for operators, indexing, and function calls.

  14. tonumber

    Convert a string or number to a number in Lua. Parses integers with bases 2-36.

  15. tostring

    Convert any Lua value to its string representation for debugging, logging, and concatenation.

  16. 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.

  17. 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...