MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / luaO_arith

Function luaO_arith

src/vm/luavm/lua/lobject.c:125–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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