int main(int argc, char **argv) { int i; char newline = '\n'; char prompt[] = "Enter a string: "; int len1, len2; char str1[80]; char str2[80]; char equal[] = "The strings are the same\n"; char diff[] = "The strings are different\n"; for (i = 0; i < argc; i++) { l_write(1, argv[i], l_strlen(argv[i])); l_write(1, &newline, 1); } while (1) { l_write(1, prompt, l_strlen(prompt)); len1 = l_gets(0, str1, 79); str1[len1] = 0; if (l_strcmp(str1, "quit\n") == 0) { break; } l_write(1, prompt, l_strlen(prompt)); len2 = l_gets(0, str2, 79); str2[len2] = 0; if (l_strcmp(str1, str2) == 0) { l_write(1, equal, l_strlen(equal)); } else { l_write(1, diff, l_strlen(diff)); } } l_exit(0); return 0; }
/* ** Main operation less than; return 'l < r'. */ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { int res; if (ttisnumber(l) && ttisnumber(r)) /* both operands are numbers? */ return LTnum(l, r); else if (ttisstring(l) && ttisstring(r)) /* both are strings? */ return l_strcmp(tsvalue(l), tsvalue(r)) < 0; else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0) /* no metamethod? */ luaG_ordererror(L, l, r); /* error */ return res; }
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { int res; if (ttisnumber(l) && ttisnumber(r)) return luai_numlt(L, nvalue(l), nvalue(r)); else if (ttisstring(l) && ttisstring(r)) return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) return res; return luaG_ordererror(L, l, r); }
int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { int res; if (ttisnumber(l) && ttisnumber(r)) return luai_numle(L, nvalue(l), nvalue(r)); else if (ttisstring(l) && ttisstring(r)) return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ return res; else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ return !res; return luaG_ordererror(L, l, r); }
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { int res; if (ttype(l) != ttype(r)) return luaG_ordererror(L, l, r); else if (ttisnumber(l)) return luai_numlt(nvalue(l), nvalue(r)); else if (ttisstring(l)) return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; #if LUA_WIDESTRING else if (ttiswstring(l)) return l_wstrcmp(rawtwsvalue(l), rawtwsvalue(r)) < 0; #endif /* LUA_WIDESTRING */ else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) return res; return luaG_ordererror(L, l, r); }
/* ** Main operation less than or equal to; return 'l <= r'. If it needs ** a metamethod and there is no '__le', try '__lt', based on ** l <= r iff !(r < l) (assuming a total order). If the metamethod ** yields during this substitution, the continuation has to know ** about it (to negate the result of r<l); bit CIST_LEQ in the call ** status keeps that information. */ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { int res; if (ttisnumber(l) && ttisnumber(r)) /* both operands are numbers? */ return LEnum(l, r); else if (ttisstring(l) && ttisstring(r)) /* both are strings? */ return l_strcmp(tsvalue(l), tsvalue(r)) <= 0; else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* try 'le' */ return res; else { /* try 'lt': */ L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */ res = luaT_callorderTM(L, r, l, TM_LT); L->ci->callstatus ^= CIST_LEQ; /* clear mark */ if (res < 0) luaG_ordererror(L, l, r); return !res; /* result is negated */ } }
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { int res; int tl= ttype(l); if (tl == ttype(r)) { switch(tl) { #ifdef LUA_TINT case LUA_TINT: return ivalue(l) < ivalue(r); #endif case LUA_TNUMBER: #ifdef LNUM_COMPLEX if ( (nvalue_img_fast(l)!=0) || (nvalue_img_fast(r)!=0) ) error_complex( L, l, r ); #endif return luai_numlt(nvalue_fast(l), nvalue_fast(r)); case LUA_TSTRING: return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; } if ((res = call_orderTM(L, l, r, TM_LT)) != -1) return res; /* fall through to 'luaG_ordererror()' */ } #ifdef LUA_TINT else if (ttype_ext(l) == ttype_ext(r)) { lua_Integer tmp; /* Avoid accuracy losing casts: if 'r' is integer by value, do comparisons * in integer realm. Only otherwise cast 'l' to FP (which might change its * value). */ # ifdef LNUM_COMPLEX if ( (nvalue_img(l)!=0) || (nvalue_img(r)!=0) ) error_complex( L, l, r ); # endif if (tl==LUA_TINT) { /* l:int, r:num */ return tt_integer_valued(r,&tmp) ? (ivalue(l) < tmp) : luai_numlt( cast_num(ivalue(l)), nvalue_fast(r) ); } else { /* l:num, r:int */ return tt_integer_valued(l,&tmp) ? (tmp < ivalue(r)) : luai_numlt( nvalue_fast(l), cast_num(ivalue(r)) ); } } #endif return luaG_ordererror(L, l, r); }
static int lessequal (lua_State *L, const TValue *l, const TValue *r) { int res; if (ttype(l) != ttype(r)) return luaG_ordererror(L, l, r); else if (ttisnumber(l)) return luai_numle(nvalue(l), nvalue(r)); else if (ttisstring(l)) return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; #if LUA_WIDESTRING else if (ttiswstring(l)) return l_wstrcmp(rawtwsvalue(l), rawtwsvalue(r)) <= 0; #endif /* LUA_WIDESTRING */ else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ return res; else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ return !res; return luaG_ordererror(L, l, r); }
static int lessequal (lua_State *L, const TValue *l, const TValue *r) { int res; int tl= ttype(l); if (tl == ttype(r)) { switch(tl) { #ifdef LUA_TINT case LUA_TINT: return ivalue(l) <= ivalue(r); #endif case LUA_TNUMBER: #ifdef LNUM_COMPLEX if ( (nvalue_img_fast(l)!=0) || (nvalue_img_fast(r)!=0) ) error_complex( L, l, r ); #endif return luai_numle(nvalue_fast(l), nvalue_fast(r)); case LUA_TSTRING: return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; } if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ return res; else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ return !res; /* fall through to 'luaG_ordererror()' */ } #ifdef LUA_TINT else if (ttype_ext(l) == ttype_ext(r)) { lua_Integer tmp; # ifdef LNUM_COMPLEX if ( (nvalue_img(l)!=0) || (nvalue_img(r)!=0) ) error_complex( L, l, r ); # endif if (tl==LUA_TINT) { /* l:int, r:num */ return tt_integer_valued(r,&tmp) ? (ivalue(l) <= tmp) : luai_numle( cast_num(ivalue(l)), nvalue_fast(r) ); } else { /* l:num, r:int */ return tt_integer_valued(l,&tmp) ? (tmp <= ivalue(r)) : luai_numle( nvalue_fast(l), cast_num(ivalue(r)) ); } } #endif return luaG_ordererror(L, l, r); }