static int fun_eq (env_t * env, int args_nr, val_t * result, val_t * args) { if (TY (0) == TY_STRING || TY (1) == TY_STRING) { stringify (&args[0], 1); stringify (&args[1], 1); RESULTINT = strcmp (ARGSTR (0), ARGSTR (1)) == 0; } else if (TY (0) == TY_DIR && TY (1) == TY_DIR) RESULTINT = ARGDIR (0) == ARGDIR (1); else if (TY (0) == TY_ENTITY && TY (1) == TY_ENTITY) RESULTINT = ARGENTITY (0) == ARGENTITY (1); else if (TY (0) == TY_LOCATION && TY (1) == TY_LOCATION) RESULTINT = (ARGLOCATION (0).x == ARGLOCATION (1).x && ARGLOCATION (0).y == ARGLOCATION (1).y && ARGLOCATION (0).m == ARGLOCATION (1).m); else if (TY (0) == TY_AREA && TY (1) == TY_AREA) RESULTINT = ARGAREA (0) == ARGAREA (1); /* Probably not that great an idea... */ else if (TY (0) == TY_SPELL && TY (1) == TY_SPELL) RESULTINT = ARGSPELL (0) == ARGSPELL (1); else if (TY (0) == TY_INVOCATION && TY (1) == TY_INVOCATION) RESULTINT = ARGINVOCATION (0) == ARGINVOCATION (1); else { intify (&args[0]); intify (&args[1]); RESULTINT = ARGINT (0) == ARGINT (1); } return 0; }
static int fun_eq(dumb_ptr<env_t>, val_t *result, const_array<val_t> args) { if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { stringify(&args[0], 1); stringify(&args[1], 1); RESULTINT = ARGSTR(0) == ARGSTR(1); } else if (ARG_TYPE(0) == TYPE::DIR && ARG_TYPE(1) == TYPE::DIR) RESULTINT = ARGDIR(0) == ARGDIR(1); else if (ARG_TYPE(0) == TYPE::ENTITY && ARG_TYPE(1) == TYPE::ENTITY) RESULTINT = ARGENTITY(0) == ARGENTITY(1); else if (ARG_TYPE(0) == TYPE::LOCATION && ARG_TYPE(1) == TYPE::LOCATION) RESULTINT = (ARGLOCATION(0).x == ARGLOCATION(1).x && ARGLOCATION(0).y == ARGLOCATION(1).y && ARGLOCATION(0).m == ARGLOCATION(1).m); else if (ARG_TYPE(0) == TYPE::AREA && ARG_TYPE(1) == TYPE::AREA) RESULTINT = ARGAREA(0) == ARGAREA(1); /* Probably not that great an idea... */ else if (ARG_TYPE(0) == TYPE::SPELL && ARG_TYPE(1) == TYPE::SPELL) RESULTINT = ARGSPELL(0) == ARGSPELL(1); else if (ARG_TYPE(0) == TYPE::INVOCATION && ARG_TYPE(1) == TYPE::INVOCATION) RESULTINT = ARGINVOCATION(0) == ARGINVOCATION(1); else { intify(&args[0]); intify(&args[1]); RESULTINT = ARGINT(0) == ARGINT(1); } return 0; }
static int fun_add (env_t * env, int args_nr, val_t * result, val_t * args) { if (TY (0) == TY_INT && TY (1) == TY_INT) { /* Integer addition */ RESULTINT = ARGINT (0) + ARGINT (1); result->ty = TY_INT; } else if (ARG_MAY_BE_AREA (0) && ARG_MAY_BE_AREA (1)) { /* Area union */ make_area (&args[0]); make_area (&args[1]); RESULTAREA = area_union (ARGAREA (0), ARGAREA (1)); ARGAREA (0) = NULL; ARGAREA (1) = NULL; result->ty = TY_AREA; } else { /* Anything else -> string concatenation */ stringify (&args[0], 1); stringify (&args[1], 1); /* Yes, we could speed this up. */ RESULTSTR = (char *) malloc (1 + strlen (ARGSTR (0)) + strlen (ARGSTR (1))); strcpy (RESULTSTR, ARGSTR (0)); strcat (RESULTSTR, ARGSTR (1)); result->ty = TY_STRING; } return 0; }
static int fun_add(dumb_ptr<env_t>, val_t *result, const_array<val_t> args) { if (ARG_TYPE(0) == TYPE::INT && ARG_TYPE(1) == TYPE::INT) { /* Integer addition */ RESULTINT = ARGINT(0) + ARGINT(1); result->ty = TYPE::INT; } else if (ARG_MAY_BE_AREA(0) && ARG_MAY_BE_AREA(1)) { /* Area union */ make_area(&args[0]); make_area(&args[1]); RESULTAREA = area_union(ARGAREA(0), ARGAREA(1)); ARGAREA(0) = NULL; ARGAREA(1) = NULL; result->ty = TYPE::AREA; } else { /* Anything else -> string concatenation */ stringify(&args[0], 1); stringify(&args[1], 1); /* Yes, we could speed this up. */ // ugh MString m; m += ARGSTR(0); m += ARGSTR(1); RESULTSTR = dumb_string::copys(FString(m)); result->ty = TYPE::STRING; } return 0; }