/* try to convert a value to an integer, rounding according to 'mode': mode == 0: accepts only integral values mode == 1: takes the floor of the number mode == 2: takes the ceil of the number  */
int luaV_tointeger(const TValue *obj, lua_Integer *p, int mode)
/* try to convert a value to an integer, rounding according to 'mode': mode == 0: accepts only integral values mode == 1: takes the floor of the number mode == 2: takes the ceil of the number  */
int luaV_tointeger(const TValue *obj, lua_Integer *p, int mode)
{
    lua_Number n = fltvalue(obj);
    lua_Number f = l_floor(n);
    if (n != f) {
      if (mode == 0) return 0;
      else if (mode > 1)
        f += 1;
    }
    return lua_numbertointeger(f, p);
  }
  else if (ttisinteger(obj)) {
    *p = ivalue(obj);
    return 1;
  }
  else if (cvt2num(obj) &&
            luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {
    obj = &v;
    goto again;
  }
  return 0;
}