/* offset(s, n, ) -> index where n-th character counting from position 'i' starts; 0 means character at 'i'.  */
static int byteoffset(lua_State *L)
/* offset(s, n, ) -> index where n-th character counting from position 'i' starts; 0 means character at 'i'.  */
static int byteoffset(lua_State *L)
{
    while (posi > 0 && iscont(s + posi)) posi--;
  }
  else {
    if (iscont(s + posi))
      return luaL_error(L, "initial position is a continuation byte");
    if (n < 0) {
       while (n < 0 && posi > 0) {
         do {
           posi--;
         } while (posi > 0 && iscont(s + posi));
         n++;
       }
     }
     else {
       n--;
       while (n > 0 && posi < (lua_Integer)len) {
         do {
           posi++;
         } while (iscont(s + posi));
         n--;
       }
     }
  }
  if (n == 0)
    lua_pushinteger(L, posi + 1);
  else
    lua_pushnil(L);
  return 1;
}