lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>I expect the first few are fine, it's really just ERRERR that's the problem.

LUA_ERRERR means an error during error handling.

>In the refman it says (pg 33, section 3.19), that almost any api 
>function can result in an error.  Are the returned error codes taken 
>from those above?  Also, lua.h says the error codes are for lua_pcall 
>and lua_load (it implies only them), but the refman says they can't 
>return error codes.  What am I missing?

The manual tries to make a difference between raising an error and returning
an error code. The primitive concept is "raising an error". That's what the
Lua core does when it can't continue. The core handles errors by longjmping
all the way back to an API function, if possible. From there, if possible, it
returns an error code identifying the error. The API functions that return
error codes are lua_pcall, lua_cpcall, and lua_load. The other API functions
"propagate" the error upwards. If the error does not happen inside a protect
call (which are initiated by one of the 3 API functions listed above), then
Lua panics. In practice, this is not common because the interpreter lua.c is
careful about this: it actually runs almost entirely inside a lua_cpcall.

Bottom line: use top-level protected calls and don't worry about the rest.
Nested proteced calls are only needed for specific tasks, such as loading
and running chunks.
--lhf