| 79 | |
| 80 | |
| 81 | static int luaB_tonumber (lua_State *L) { |
| 82 | if (lua_isnoneornil(L, 2)) { /* standard conversion? */ |
| 83 | if (lua_type(L, 1) == LUA_TNUMBER) { /* already a number? */ |
| 84 | lua_settop(L, 1); /* yes; return it */ |
| 85 | return 1; |
| 86 | } |
| 87 | else { |
| 88 | size_t l; |
| 89 | const char *s = lua_tolstring(L, 1, &l); |
| 90 | if (s != NULL && lua_stringtonumber(L, s) == l + 1) |
| 91 | return 1; /* successful conversion to number */ |
| 92 | /* else not a number */ |
| 93 | luaL_checkany(L, 1); /* (but there must be some parameter) */ |
| 94 | } |
| 95 | } |
| 96 | else { |
| 97 | size_t l; |
| 98 | const char *s; |
| 99 | lua_Integer n = 0; /* to avoid warnings */ |
| 100 | lua_Integer base = luaL_checkinteger(L, 2); |
| 101 | luaL_checktype(L, 1, LUA_TSTRING); /* no numbers as strings */ |
| 102 | s = lua_tolstring(L, 1, &l); |
| 103 | luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); |
| 104 | if (b_str2int(s, (int)base, &n) == s + l) { |
| 105 | lua_pushinteger(L, n); |
| 106 | return 1; |
| 107 | } /* else not a number */ |
| 108 | } /* else not a number */ |
| 109 | luaL_pushfail(L); /* not a number */ |
| 110 | return 1; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | static int luaB_error (lua_State *L) { |
nothing calls this directly
no test coverage detected