MCPcopy Create free account
hub / github.com/defold/defold / luaB_tonumber

Function luaB_tonumber

engine/lua/src/lua/lbaselib.c:53–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51
52
53static 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
81static int luaB_error (lua_State *L) {

Callers

nothing calls this directly

Calls 5

luaL_checkanyFunction · 0.85
lua_isnumberFunction · 0.85
lua_pushnumberFunction · 0.85
lua_tonumberFunction · 0.85
lua_pushnilFunction · 0.85

Tested by

no test coverage detected