lua-users home
lua-l archive

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


A simpler and more consistent interface may be:

void lua_seterrorf(lua_State *L, int index);  [-1, +0]

where index is the stack index of a function to be used as the error function.

If a context pointer is useful, that could be part of a closure.

This could optionally be paired with a

void lua_geterrorf(lua_State *L); [-0, +1]

function that would push the function on to the top of the stack, or
nil if no function was set. This would enable wrapping previous error
functions to chain them or to temporarily change them.

An alternative approach may be to introduce a new pseudo-index such as
LUA_ERRORF. That location would hold either nil, the default, or the
function to be called on an error.

I prefer the lua_{set,get}errorf interface because it would be more
explicitly documented, and I would consider the code slightly more
readable. The pseudo-index has the advantage of being a minimal change
to the existing API.