MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / luaV_tointeger

Function luaV_tointeger

src/Chain/libraries/glua/lvm.cpp:107–130  ·  view source on GitHub ↗

** try to convert a value to an integer, rounding according to 'mode': ** mode == 0: accepts only integral values ** mode == 1: takes the floor of the number ** mode == 2: takes the ceil of the number */

Source from the content-addressed store, hash-verified

105** mode == 2: takes the ceil of the number
106*/
107int luaV_tointeger(const TValue *obj, lua_Integer *p, int mode) {
108 TValue v;
109again:
110 if (ttisfloat(obj)) {
111 lua_Number n = fltvalue(obj);
112 lua_Number f = l_floor(n);
113 if (n != f) { /* not an integral value? */
114 if (mode == 0) return 0; /* fails if mode demands integral value */
115 else if (mode > 1) /* needs ceil? */
116 f += 1; /* convert floor to ceil (remember: n != f) */
117 }
118 return lua_numbertointeger(f, p);
119 }
120 else if (ttisinteger(obj)) {
121 *p = ivalue(obj);
122 return 1;
123 }
124 else if (cvt2num(obj) &&
125 luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {
126 obj = &v;
127 goto again; /* convert result from 'luaO_str2num' to an integer */
128 }
129 return 0; /* conversion failed */
130}
131
132
133/*

Callers 3

forlimitFunction · 0.85
luaH_newkeyFunction · 0.85
luaH_getFunction · 0.85

Calls 1

luaO_str2numFunction · 0.85

Tested by

no test coverage detected