query_action() Peter Eriksson Description: Below follow what changes are needed to implement the function query_action() which returns information about registered actions for a certain object. Usage: string *query_action(string|object); mixed *query_action(string|object, string); Example: foo() { string *actionlist; int i; actionlist = query_action("lpd"); for (i = 0; i < sizeof(actionlist); i++) write(actionlist[i] + "\n"); } bar() { mixed *actiondesc; actiondesc = query_action("lpd", "south"); write("Short_verb_flag = " + actiondesc[0] + "\n"); write("Function name = " + actiondesc[1] + "\n"); write("Object file = " + file_name(actiondesc[2]) + "\n"); } Patchlist: func_spec.c: Add this in alphabetic order in the list of functions: mixed *query_action(string|object, void|string); interpret.c: Add this in the huge switch with all the EFUNs: #ifdef F_QUERY_ACTION CASE(F_QUERY_ACTION); { struct vector *v; struct svalue *arg; struct svalue *level; if (!command_giver) error("query_action(): illegal usage\n"); level = sapply("query_level", command_giver, 0); if (!level || level->type != T_NUMBER) error("query_action(): query_level returned illegal value\n"); arg = sp - num_arg + 1; if (arg[0].type == T_OBJECT) ob = arg[0].u.ob; else { ob = find_object(arg[0].u.string); if (ob == 0) error("query_action() failed\n"); } if (ob->interactive && ob != command_giver && level->u.number < 22) error("query_action(): illegal usage\n"); if (num_arg > 1) v = get_action(ob, arg[1].u.string); else v = get_all_actions(ob); pop_n_elems(num_arg); if (v) { push_vector(v); v->ref--; } else push_number(0); } break; #endif simulate.c: Add the following after the definition of 'print_local_commands()': struct vector *get_action(ob, verb) struct object *ob; char *verb; { struct vector *v; struct sentence *s; for (s = ob->sent; s; s = s->next) if (strcmp(verb, s->verb) == 0) break; if (!s) return NULL; v = allocate_array(3); v->item[0].type = T_NUMBER; v->item[0].u.number = s->short_verb; v->item[1].type = T_STRING; v->item[1].string_type = STRING_MALLOC; v->item[1].u.string = string_copy(s->function); v->item[2].type = T_OBJECT; v->item[2].u.ob = s->ob; add_ref(s->ob, "get_action"); return v; } struct vector *get_all_actions(ob) struct object *ob; { struct vector *v; struct sentence *s; int num; num = 0; for (s = ob->sent; s; s = s->next) num++; if (num == 0) return NULL; v = allocate_array(num); num = 0; for (s = ob->sent; s; s = s->next) { v->item[num].type = T_STRING; v->item[num].string_type = STRING_MALLOC; v->item[num].u.string = string_copy(s->verb); num++; } return v; }