** Main operation less than; return 'l < r'. */
| 384 | ** Main operation less than; return 'l < r'. |
| 385 | */ |
| 386 | int luaV_lessthan(lua_State *L, const TValue *l, const TValue *r) { |
| 387 | int res; |
| 388 | if (ttisnumber(l) && ttisnumber(r)) /* both operands are numbers? */ |
| 389 | return LTnum(l, r); |
| 390 | else if (ttisstring(l) && ttisstring(r)) /* both are strings? */ |
| 391 | return l_strcmp(tsvalue(l), tsvalue(r)) < 0; |
| 392 | else if (ttisstring(l) && ttisnumber(r)) |
| 393 | { |
| 394 | auto lstr = svalue(l); |
| 395 | auto rstr = std::to_string(ttisinteger(r) ? ivalue(r) : fltvalue(r)); |
| 396 | return l_c_str_cmp(lstr, rstr.c_str()); |
| 397 | } |
| 398 | else if(ttisnumber(l) && ttisstring(r)) |
| 399 | { |
| 400 | auto lstr = std::to_string(ttisinteger(l) ? ivalue(l) : fltvalue(l)); |
| 401 | auto rstr = svalue(r); |
| 402 | return l_c_str_cmp(lstr.c_str(), rstr); |
| 403 | } |
| 404 | else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0) /* no metamethod? */ |
| 405 | luaG_ordererror(L, l, r); /* error */ |
| 406 | return res; |
| 407 | } |
| 408 | |
| 409 | |
| 410 | /* |
no test coverage detected