/* get information about the i-th capture. If there are no captures and 'i==0', return information about the whole match, which is the range 's'..'e'. If the capture is a string, return its length and put its address in '*cap'. If it is an integer (a position), push it on the stack and return CAP_POSITION.  */
static size_t get_onecapture(MatchState *ms, int i, const char *s, const char *e, const char **cap)
/* get information about the i-th capture. If there are no captures and 'i==0', return information about the whole match, which is the range 's'..'e'. If the capture is a string, return its length and put its address in '*cap'. If it is an integer (a position), push it on the stack and return CAP_POSITION.  */
static size_t get_onecapture(MatchState *ms, int i, const char *s, const char *e, const char **cap)
{
  if (i >= ms->level) {
    if (l_unlikely(i != 0))
      luaL_error(ms->L, "invalid capture index %%%d", i + 1);
    *cap = s;
    return e - s;
  }
  else {
    ptrdiff_t capl = ms->capture[i].len;
    *cap = ms->capture[i].init;
    if (l_unlikely(capl == CAP_UNFINISHED))
      luaL_error(ms->L, "unfinished capture");
    else if (capl == CAP_POSITION)
      lua_pushinteger(ms->L, (ms->capture[i].init - ms->src_init) + 1);
    return capl;
  }
}