MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaO_arith

Function luaO_arith

depends/lua/src/lobject.c:123–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121
122
123void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,
124 TValue *res) {
125 switch (op) {
126 case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:
127 case LUA_OPSHL: case LUA_OPSHR:
128 case LUA_OPBNOT: { /* operate only on integers */
129 lua_Integer i1; lua_Integer i2;
130 if (tointeger(p1, &i1) && tointeger(p2, &i2)) {
131 setivalue(res, intarith(L, op, i1, i2));
132 return;
133 }
134 else break; /* go to the end */
135 }
136 case LUA_OPDIV: case LUA_OPPOW: { /* operate only on floats */
137 lua_Number n1; lua_Number n2;
138 if (tonumber(p1, &n1) && tonumber(p2, &n2)) {
139 setfltvalue(res, numarith(L, op, n1, n2));
140 return;
141 }
142 else break; /* go to the end */
143 }
144 default: { /* other operations */
145 lua_Number n1; lua_Number n2;
146 if (ttisinteger(p1) && ttisinteger(p2)) {
147 setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2)));
148 return;
149 }
150 else if (tonumber(p1, &n1) && tonumber(p2, &n2)) {
151 setfltvalue(res, numarith(L, op, n1, n2));
152 return;
153 }
154 else break; /* go to the end */
155 }
156 }
157 /* could not perform raw operation; try metamethod */
158 lua_assert(L != NULL); /* should not fail when folding (compile time) */
159 luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD));
160}
161
162
163int luaO_hexavalue (int c) {

Callers 2

lua_arithFunction · 0.85
constfoldingFunction · 0.85

Calls 4

intarithFunction · 0.85
numarithFunction · 0.85
luaT_trybinTMFunction · 0.85
castFunction · 0.85

Tested by

no test coverage detected