lua-users home
lua-l archive

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


Hi Benoit,

On Mon, May 3, 2010 at 12:52 PM, Benoit Germain <bgermain@ubisoft.fr> wrote:
> When I code a binding, I find myself having helper functions manipulating
> items on the stack whose index is provided by the caller. Often enough, this
> index is relative to the stack top.

The usual approach to tackling this problem is pushing the index first
thing before doing any other operations:

static void example (lua_State *L, int idx)
{
  lua_pushvalue(L, idx);
  // do stuff with relative index -1
}

Naturally this won't work if you provide more than one index (other
solutions are needed).

-- 
- Patrick Donnelly