Dealing with relative indices in Lua APIs

When you use the Lua C API to implement custom Lua bindings, you inevitably end up with internal helper functions that accept a Lua stack index. Lua stack indicies can be positive, which indicates an index from the bottom of the stack or negative, which is an index from the top of the stack. It is extremely common to pass -1 to functions to indicate they should operate on the value at the top of the stack.
Read more...