MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / luaB_tonumber

Function luaB_tonumber

Source/Misc/lua/src/lua.c:10917–10942  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10915
10916
10917static int luaB_tonumber (lua_State *L) {
10918int base = luaL_optint(L, 2, 10);
10919if (base == 10) { /* standard conversion */
10920luaL_checkany(L, 1);
10921if (lua_isnumber(L, 1)) {
10922lua_pushnumber(L, lua_tonumber(L, 1));
10923return 1;
10924}
10925}
10926else {
10927const char *s1 = luaL_checkstring(L, 1);
10928char *s2;
10929unsigned long n;
10930luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
10931n = strtoul(s1, &s2, base);
10932if (s1 != s2) { /* at least one valid digit? */
10933while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */
10934if (*s2 == '\0') { /* no invalid trailing characters? */
10935lua_pushnumber(L, (lua_Number)n);
10936return 1;
10937}
10938}
10939}
10940lua_pushnil(L); /* else not a number */
10941return 1;
10942}
10943
10944
10945static int luaB_error (lua_State *L) {

Callers

nothing calls this directly

Calls 5

luaL_checkanyFunction · 0.85
lua_isnumberFunction · 0.85
lua_pushnumberFunction · 0.85
lua_tonumberFunction · 0.85
lua_pushnilFunction · 0.85

Tested by

no test coverage detected