MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / l_str2int

Function l_str2int

third-party/lua-5.5.0/src/lobject.c:339–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337#define MAXLASTD cast_int(LUA_MAXINTEGER % 10)
338
339static const char *l_str2int (const char *s, lua_Integer *result) {
340 lua_Unsigned a = 0;
341 int empty = 1;
342 int neg;
343 while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */
344 neg = isneg(&s);
345 if (s[0] == '0' &&
346 (s[1] == 'x' || s[1] == 'X')) { /* hex? */
347 s += 2; /* skip '0x' */
348 for (; lisxdigit(cast_uchar(*s)); s++) {
349 a = a * 16 + luaO_hexavalue(*s);
350 empty = 0;
351 }
352 }
353 else { /* decimal */
354 for (; lisdigit(cast_uchar(*s)); s++) {
355 int d = *s - '0';
356 if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */
357 return NULL; /* do not accept it (as integer) */
358 a = a * 10 + cast_uint(d);
359 empty = 0;
360 }
361 }
362 while (lisspace(cast_uchar(*s))) s++; /* skip trailing spaces */
363 if (empty || *s != '\0') return NULL; /* something wrong in the numeral */
364 else {
365 *result = l_castU2S((neg) ? 0u - a : a);
366 return s;
367 }
368}
369
370
371size_t luaO_str2num (const char *s, TValue *o) {

Callers 1

luaO_str2numFunction · 0.70

Calls 2

isnegFunction · 0.70
luaO_hexavalueFunction · 0.70

Tested by

no test coverage detected