| 67 | |
| 68 | |
| 69 | static int luaB_tonumber (lua_State *L) { |
| 70 | if (lua_isnoneornil(L, 2)) { /* standard conversion? */ |
| 71 | luaL_checkany(L, 1); |
| 72 | if (lua_type(L, 1) == LUA_TNUMBER) { /* already a number? */ |
| 73 | lua_settop(L, 1); /* yes; return it */ |
| 74 | return 1; |
| 75 | } |
| 76 | else { |
| 77 | size_t l; |
| 78 | const char *s = lua_tolstring(L, 1, &l); |
| 79 | if (s != NULL && lua_stringtonumber(L, s) == l + 1) |
| 80 | return 1; /* successful conversion to number */ |
| 81 | /* else not a number */ |
| 82 | } |
| 83 | } |
| 84 | else { |
| 85 | size_t l; |
| 86 | const char *s; |
| 87 | lua_Integer n = 0; /* to avoid warnings */ |
| 88 | lua_Integer base = luaL_checkinteger(L, 2); |
| 89 | luaL_checktype(L, 1, LUA_TSTRING); /* no numbers as strings */ |
| 90 | s = lua_tolstring(L, 1, &l); |
| 91 | luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); |
| 92 | if (b_str2int(s, (int)base, &n) == s + l) { |
| 93 | lua_pushinteger(L, n); |
| 94 | return 1; |
| 95 | } /* else not a number */ |
| 96 | } /* else not a number */ |
| 97 | lua_pushnil(L); /* not a number */ |
| 98 | return 1; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | static int luaB_error (lua_State *L) { |
nothing calls this directly
no test coverage detected