private static StringPointer startCapture ( MatchState ms, StringPointer s, StringPointer p, int what ) {
        StringPointer res;
        int level = ms.level;
        BaseLib.luaAssert(level < LUA_MAXCAPTURES, "too many captures");

        ms.capture[level].init = s.getClone();
        ms.capture[level].init.setIndex ( s.getIndex () );
        ms.capture[level].len = what;
        ms.level = level + 1;
        if ( ( res = match ( ms, s, p ) ) == null ) /* match failed? */ {
            ms.level --;  /* undo capture */
        }
        return res;
    }
Only works with non-negative numbers
main/src/main/java/cgeo/geocaching/wherigo/kahlua/stdlib/StringLib.java