Lua.VM.ArgumentError exception (Lua v1.0.0-rc.2)
View SourceRaised 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 fromLua.VM.Executor.current_position/0when 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.
Builds the PUC-Lua "wrong number of arguments to 'X'" runtime error.
Types
Functions
@spec type_error(String.t(), pos_integer(), String.t(), String.t()) :: t()
Creates an ArgumentError for type mismatches.
Example
ArgumentError.type_error("string.rep", 2, "number", "string")
@spec value_expected(String.t(), pos_integer()) :: t()
Creates an ArgumentError when no value is provided for a required argument.
Example
ArgumentError.value_expected("string.lower", 1)
@spec wrong_number_of_arguments(String.t()) :: Lua.VM.RuntimeError.t()
Builds the PUC-Lua "wrong number of arguments to 'X'" runtime error.
This is not a bad-argument error — it is the top-level message PUC-Lua's
luaL_error(L, "wrong number of arguments to '%s'", name) emits when a
variadic stdlib function is called with too few or too many positional
arguments. Returns a Lua.VM.RuntimeError so callers can raise it
directly:
raise ArgumentError.wrong_number_of_arguments("insert")