MCPcopy Create free account
hub / github.com/BigPig0/RelayLive / luaO_arith

Function luaO_arith

ThirdParty/lua/lua/lobject.c:116–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

lua_arithFunction · 0.85
constfoldingFunction · 0.85

Calls 3

intarithFunction · 0.85
numarithFunction · 0.85
luaT_trybinTMFunction · 0.85

Tested by

no test coverage detected