Lua.VM.ArgumentError exception (Lua v1.0.0-rc.0)

View Source

Raised when a function is called with invalid arguments.

This exception provides standardized error messages for bad arguments across all Lua standard library functions.

Fields

  • :function_name - The fully qualified function name (e.g., "string.rep")
  • :arg_num - The argument number (1-based)
  • :expected - What type or value was expected (e.g., "number", "string")
  • :got - What was actually received (optional, e.g., "nil", "boolean")
  • :details - Additional details about the error (optional)
  • :line - Source line where the call originated (auto-populated from Lua.VM.Executor.current_position/0 when not given explicitly)
  • :source - Source name where the call originated (auto-populated)
  • :call_stack - Call stack frames at the raise site (default [])

Examples

# Basic type error — line/source filled in automatically when raised
# from inside a Lua execution.
raise ArgumentError,
  function_name: "string.rep",
  arg_num: 2,
  expected: "number"

# With actual type received
raise ArgumentError,
  function_name: "string.sub",
  arg_num: 2,
  expected: "number",
  got: "string"

# With additional details
raise ArgumentError,
  function_name: "string.char",
  arg_num: 1,
  expected: "number",
  details: "value out of range"

Summary

Functions

Creates an ArgumentError for type mismatches.

Creates an ArgumentError when no value is provided for a required argument.

Functions

type_error(function_name, arg_num, expected, got)

Creates an ArgumentError for type mismatches.

Example

ArgumentError.type_error("string.rep", 2, "number", "string")

value_expected(function_name, arg_num)

Creates an ArgumentError when no value is provided for a required argument.

Example

ArgumentError.value_expected("string.lower", 1)