lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 02.06.2011 18:24, schrieb Marc Balmer:
Am 02.06.2011 18:19, schrieb Marc Balmer:
Am 02.06.2011 18:05, schrieb Luiz Henrique de Figueiredo:
syntax error: [string "return 42"]:1: malformed number near '42ÿ'

Ah, ÿ is 0xFF. So, somehow -1 is getting mapped into 0xFF.
It seems to be a faulty isdigit, which is mapping -1 to 0xFF *and*
thinking 0xFF is a digit! Try using your own isdigit...

Where does that -1 come from? I replaced isdigit() in read_numeral by
the following, no change:

static int
isadigit(char c)
{
if (c >= '0' && c <= '9')
return 1;
return 0;
}




If you want to trace this, the place to start is read_numeral in llex.c.

isalnum(-1) indeed returns != 0 on Windows Mobile. Looks like a
signed/unsigned char, Unicode or related problem to me.

When I change read_numeral from

static void read_numeral (LexState *ls, SemInfo *seminfo) {
  lua_assert(isdigit(ls->current));
  do {
    save_and_next(ls);
  } while (isdigit(ls->current) || ls->current == '.');
  if (check_next(ls, "Ee"))  /* `E'? */
    check_next(ls, "+-");  /* optional exponent sign */
  while (isalnum(ls->current) || ls->current == '_')
    save_and_next(ls);
  save(ls, '\0');
buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
  if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r))  /* format error? */
    trydecpoint(ls, seminfo); /* try to update decimal point separator */
}

to

static void read_numeral (LexState *ls, SemInfo *seminfo) {
  lua_assert(isdigit(ls->current));
  do {
    save_and_next(ls);
  } while (isdigit(ls->current) || ls->current == '.');
  if (check_next(ls, "Ee"))  /* `E'? */
    check_next(ls, "+-");  /* optional exponent sign */
  while (isdigit(ls->current) || ls->current == '_')
    save_and_next(ls);
  save(ls, '\0');
buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
  if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r))  /* format error? */
    trydecpoint(ls, seminfo); /* try to update decimal point separator */
}


It works. Note that I changed the "isalnum" to "isdigit" in the second loop. Why is isalnum() being used there?