MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / luaB_tonumber

Function luaB_tonumber

3rd/lua-5.4.3/src/lbaselib.c:81–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79
80
81static 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
114static int luaB_error (lua_State *L) {

Callers

nothing calls this directly

Calls 9

lua_typeFunction · 0.85
lua_settopFunction · 0.85
lua_tolstringFunction · 0.85
lua_stringtonumberFunction · 0.85
luaL_checkanyFunction · 0.85
luaL_checkintegerFunction · 0.85
luaL_checktypeFunction · 0.85
b_str2intFunction · 0.85
lua_pushintegerFunction · 0.85

Tested by

no test coverage detected