Because Lua is an extension language, all Lua actions start from C code calling a function from the Lua library. Whenever an error occurs during Lua compilation or execution, an error fallback function is called, and then the corresponding function from the library (lua_dofile , lua_dostring , lua_call , and lua_callfunction ) is terminated returning an error condition.
The only argument to the error fallback function is a string describing the error. The standard I/O library redefines this fallback, using the debug facilities (see Section 7, in order to print some extra informations, like the stack of calls. For more information about an error, the Lua program can include the compilation pragma $debug . This pragma must be written in a line by itself. When an error occurs in a program compiled with this option, the error routine is able to print also the lines where the calls (and the error) were made. If needed, it is possible to change the error fallback routine; see Section 4.7.
Lua code can generate an error by calling the function error . Its optional parameter is a string, which is used as the error message.