* crecall() [AEJ]
* @poll with no argument now displays the current poll; use
@poll/clear to clear it [AEJ]
+ * default() can take multiple attributes to try in order [AEJ]
the string and the same password.
& DEFAULT()
- Function: default([<obj>/]<attr>,<default case>)
-
- This function returns the value of <obj>/<attr>, as if retrieved via
- the get() function, if the attribute exists and is readable by you.
- Otherwise, it evaluates the default case, and returns that.
- Note that the default case is only evaluated if the attribute does
- not exist or cannot be read. Note further than an empty attribute
- counts as an existing attribute.
+ Function: default([<obj>/]<attr>,[[<obj>]/<attr>,...]<default case>)
+ This function returns the value of the first possible <obj>/<attr>,
+ as if retrieved via the get() function, if the attribute exists and
+ is readable by you. Otherwise, it evaluates the default case, and
+ returns that. Note that the default case is only evaluated if the
+ attribute does not exist or cannot be read. Note further that an
+ empty attribute counts as an existing attribute.
+
This is useful for code that needs to return the value of an attribute,
or an error message or default case, if that attribute does not exist.
{"DEC", fun_dec, 1, 1, FN_REG},
{"DECOMPOSE", fun_decompose, 1, -1, FN_REG},
{"DECRYPT", fun_decrypt, 2, 2, FN_REG},
- {"DEFAULT", fun_default, 2, 2, FN_NOPARSE},
+ {"DEFAULT", fun_default, 2, INT_MAX, FN_NOPARSE},
{"DELETE", fun_delete, 3, 3, FN_REG},
{"DIE", fun_die, 2, 3, FN_REG},
{"DIG", fun_dig, 1, 3, FN_REG},
char *dp;
const char *sp;
char mstr[BUFFER_LEN];
+ int i;
/* find our object and attribute */
- dp = mstr;
- sp = args[0];
- process_expression(mstr, &dp, &sp, executor, caller, enactor,
- PE_DEFAULT, PT_DEFAULT, pe_info);
- *dp = '\0';
- parse_attrib(executor, mstr, &thing, &attrib);
- if (GoodObject(thing) && attrib && Can_Read_Attr(executor, thing, attrib)) {
- /* Ok, we've got it */
- dp = safe_atr_value(attrib);
- safe_str(dp, buff, bp);
- free(dp);
- return;
+ for (i = 1; i < nargs; i++) {
+ mstr[0] = '\0';
+ dp = mstr;
+ sp = args[i - 1];
+ process_expression(mstr, &dp, &sp, executor, caller, enactor, PE_DEFAULT,
+ PT_DEFAULT, pe_info);
+ *dp = '\0';
+ parse_attrib(executor, mstr, &thing, &attrib);
+ if (GoodObject(thing) && attrib && Can_Read_Attr(executor, thing, attrib)) {
+ /* Ok, we've got it */
+ dp = safe_atr_value(attrib);
+ safe_str(dp, buff, bp);
+ free(dp);
+ return;
+ }
}
- /* We couldn't get it. Evaluate args[1] and return it */
- sp = args[1];
+ /* We couldn't get it. Evaluate the last arg and return it */
+ sp = args[nargs - 1];
process_expression(buff, bp, &sp, executor, caller, enactor,
PE_DEFAULT, PT_DEFAULT, pe_info);
return;