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