Function pcall

Source
pub unsafe extern "C" fn pcall(
    state: lua_State,
    nargs: i32,
    nrets: i32,
    errfunc: i32,
) -> Status
Expand description

Calls a function in protected mode.

Both nargs and nresults have the same meaning as in call (lua_call). If there are no errors during the call, pcall (lua_pcall) behaves exactly like call (lua_call). However, if there is any error, pcall (lua_pcall) catches it, pushes a single value on the stack (the error message), and returns an error code. Like call (lua_call), pcall (lua_pcall) always removes the function and its arguments from the stack.

If errfunc is 0, then the error message returned on the stack is exactly the original error message. Otherwise, errfunc is the stack index of an error handler function. (In the current implementation, this index cannot be a pseudo-index.) In case of runtime errors, this function will be called with the error message and its return value will be the message returned on the stack by pcall (lua_pcall).