lua-users home
lua-l archive

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


On 2/23/06, Javier Guerra <javier@guerrag.com> wrote:
On Thursday 23 February 2006 11:50 am, Chris wrote:
> That made me think, a substring style unpack could be useful.

this seems to work:

I would hack the actual unpack function Lua uses (maybe creating a new version).  I'm just writing this right here so I don't know if this code works:

static int luaB_unpack (lua_State *L) {
  int n, i;
  luaL_checktype(L, 1, LUA_TTABLE);
  i = luaL_optint(L, 2, 1);
  n = luaL_optint(L, 3, luaL_getn(L, 1));
  luaL_checkstack(L, n, "table too big to unpack");
  for (i=1; i<=n; i++)  /* push arg[1...n] */
    lua_rawgeti(L, 1, i);
  return n;
}

Should not be much slower than the real unpack.

--
// Chris