Example #1
0
int luaO_str2d (const char *s, lua_Number *result) {
  char *endptr;
  *result = lua_str2number(s, &endptr);
  if (endptr == s) return 0;  /* conversion failed */
  if (*endptr == 'x' || *endptr == 'X')  /* maybe an hexadecimal constant? */
#if defined(LUA_CROSS_COMPILER) 
    {
    long lres = strtoul(s, &endptr, 16);
#if LONG_MAX != 2147483647L
    if (lres & ~0xffffffffL) 
      *result = cast_num(-1);
    else if (lres & 0x80000000L)
      *result = cast_num(lres | ~0x7fffffffL);
    else
#endif
      *result = cast_num(lres);
    }
#else
    *result = cast_num(c_strtoul(s, &endptr, 16));
#endif
  if (*endptr == '\0') return 1;  /* most common case */
  while (isspace(cast(unsigned char, *endptr))) endptr++;
  if (*endptr != '\0') return 0;  /* invalid trailing characters? */
  return 1;
}
Example #2
0
bool StringToNumber(const char* string, lua_Number* result)
{

    char* end;
    *result = lua_str2number(string, &end);

    if (end == string)
    {
        // The conversion failed.
        return false;
    }
    if (*end == 'x' || *end == 'X')
    {
        // Try converting as a hexadecimal number.
        *result = strtoul(string, &end, 16);
    }
    // Allow trailing spaces.
    while (isspace(*end))
    {
        ++end;
    }
    if (*end == '\0')
    {
        // Converted the entire string.
        return true;
    }

    return false;

}
Example #3
0
int luaO_str2d (const char *s, lua_Number *result) {
  char *endptr;
  *result = lua_str2number(s, &endptr);
  if (endptr == s) return 0;  /* conversion failed */
  if (*endptr == 'x' || *endptr == 'X')  /* maybe an hexadecimal constant? */
    *result = cast_num(strtoul(s, &endptr, 16));
  if (*endptr == '\0') return 1;  /* most common case */
  while (isspace(cast(unsigned char, *endptr))) endptr++;
  if (*endptr != '\0') return 0;  /* invalid trailing characters? */
  return 1;
}
Example #4
0
int luaO_str2d (const char *s, size_t len, lua_Number *result) {
  char *endptr;
  if (strpbrk(s, "nN"))  /* reject 'inf' and 'nan' */
    return 0;
  else if (strpbrk(s, "xX"))  /* hexa? */
    *result = lua_strx2number(s, &endptr);
  else
    *result = lua_str2number(s, &endptr);
  if (endptr == s) return 0;  /* nothing recognized */
  while (lisspace(cast_uchar(*endptr))) endptr++;
  return (endptr == s + len);  /* OK if no trailing characters */
}
Example #5
0
COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s) {
  char* endptr;
  lua_Number n = lua_str2number(s, &endptr);
  if (endptr != s) {
    while (*endptr != '\0' && isspace((unsigned char)*endptr))
      ++endptr;
    if (*endptr == '\0') {
      lua_pushnumber(L, n);
      return endptr - s + 1;
    }
  }
  return 0;
}
Example #6
0
int luaO_str2d (const char *s, lua_Number *result) {
  char *endptr;

  // MTA modification (From Lua 5.2)
  if (strpbrk(s, "nN"))  /* reject 'inf' and 'nan' */
    return 0;

  *result = lua_str2number(s, &endptr);
  if (endptr == s) return 0;  /* conversion failed */
  if (*endptr == 'x' || *endptr == 'X')  /* maybe an hexadecimal constant? */
    *result = cast_num(strtoul(s, &endptr, 16));
  if (*endptr == '\0') return 1;  /* most common case */
  while (isspace(cast(unsigned char, *endptr))) endptr++;
  if (*endptr != '\0') return 0;  /* invalid trailing characters? */
  return 1;
}