MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / luaV_tointeger

Function luaV_tointeger

libraries/AP_Scripting/lua/src/lvm.c:98–121  ·  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

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

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