| 51 | |
| 52 | |
| 53 | static int luaB_tonumber (lua_State *L) { |
| 54 | int base = luaL_optint(L, 2, 10); |
| 55 | if (base == 10) { /* standard conversion */ |
| 56 | luaL_checkany(L, 1); |
| 57 | if (lua_isnumber(L, 1)) { |
| 58 | lua_pushnumber(L, lua_tonumber(L, 1)); |
| 59 | return 1; |
| 60 | } |
| 61 | } |
| 62 | else { |
| 63 | const char *s1 = luaL_checkstring(L, 1); |
| 64 | char *s2; |
| 65 | unsigned long n; |
| 66 | luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); |
| 67 | n = strtoul(s1, &s2, base); |
| 68 | if (s1 != s2) { /* at least one valid digit? */ |
| 69 | while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ |
| 70 | if (*s2 == '\0') { /* no invalid trailing characters? */ |
| 71 | lua_pushnumber(L, (lua_Number)n); |
| 72 | return 1; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | lua_pushnil(L); /* else not a number */ |
| 77 | return 1; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | static int luaB_error (lua_State *L) { |
nothing calls this directly
no test coverage detected