& @function
@function [<function name>]
- @function <name>=<obj>,<attrib>[,<min args>, <max args>[,<restrictions>]]
+ @function[/preserve] <name>=<obj>,<attrib>[,<min args>,
+ <max args>[,<restrictions>]]
or @function <function name>=<object>/<attribute>
@function/<switch> <function name>
+ @function/restrict <function name>=<restrictions>
When used without any arguments, this command lists all global
user-defined functions. For Directors and others with the Functions
/disable, to disable a built in function.
/enable, to re-enable it.
/delete, to remove a user-defined function.
+ /restrict, to change the restriction flags on an existing function.
Otherwise, this command defines a global function with the name
<function name>, which evaluates to <attribute> on <object>.
+(continued in help @function2)
+& @function2
<object> can be anything that the player using the @function command
controls. <function name> must be 30 characters or less.
-(continued in help @function2)
-& @function2
A function defined using @function works just like any of the normal
MUSH functions, from the user's perspective. The functions are
executed by the object, with its powers.
Functions defined via @function should follow the format used by
UFUN() - %0 is the first argument passed, %1 is the second argument
- passed, and so forth. Option third and fourth arguments to @function
+ passed, and so forth. Optional third and fourth arguments to @function
can be used to set a parser-enforced number of arguments for the function.
+ An optional fifth argument will set restriction flags.
+
+ The /preserve switch, for MUX compatibility, does the same thing as the
+ 'localize' restriction - treats the attribute that's evaluated as if it
+ were called with ulocal() instead of u().
Example:
@function/restore will delete the @function and turn the built in
version back on.
+ Using @function on an already-added function will delete the old one and
+ install a new function with none of the settings of the old one kept.
+
For example:
@function/delete ansi
&ansi_fun #1234=%0
extern void do_function_restore(dbref player, const char *name);
extern void do_list_functions(dbref player, int lc);
extern char *list_functions(void);
-extern void do_function(dbref player, char *name, char **argv);
+extern void do_function(dbref player, char *name, char **argv, int preserve);
extern void do_function_toggle(dbref player, char *name, int toggle);
extern void do_function_report(dbref player, char *name);
extern void do_function_delete(dbref player, char *name);
*args_right[2]++ = '\0';
}
if (args_right[1] && *args_right[1])
- do_function(player, arg_left, args_right);
+ do_function(player, arg_left, args_right, SW_ISSET(sw, SWITCH_PRESERVE));
else if (arg_left && *arg_left)
do_function_report(player, arg_left);
else
- do_function(player, NULL, NULL);
+ do_function(player, NULL, NULL, 0);
if (split) {
if (args_right[2])
*--args_right[2] = '/';
{"@FORCE", "NOEVAL", cmd_force, CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_NOGAGGED,
NULL},
- {"@FUNCTION", "DELETE ENABLE DISABLE RESTORE RESTRICT", cmd_function,
+ {"@FUNCTION", "DELETE ENABLE DISABLE PRESERVE RESTORE RESTRICT", cmd_function,
CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_RS_ARGS | CMD_T_NOGAGGED, NULL},
{"@GREP", "LIST PRINT ILIST IPRINT", cmd_grep,
CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_RS_NOPARSE | CMD_T_NOGAGGED, NULL},
* \param player the enactor.
* \param name name of function to add.
* \param argv array of arguments.
+ * \param preserve Treat the function like it was called with ulocal() instead
+ * of u().
*/
void
-do_function(dbref player, char *name, char *argv[])
+do_function(dbref player, char *name, char *argv[], int preserve)
{
char tbuf1[BUFFER_LEN];
char *bp = tbuf1;
fp->flags = apply_restrictions(0, argv[5]);
else
fp->flags = 0;
+ if (preserve)
+ fp->flags |= FN_LOCALIZE;
hashadd(name, fp, &htab_user_function);
/* now add it to the user function table */
} else
fp->maxargs = 10;
+ /* Set new flags */
if (argv[5] && *argv[5])
fp->flags = apply_restrictions(0, argv[5]);
else
fp->flags = 0;
+ if (preserve)
+ fp->flags |= FN_LOCALIZE;
notify(player, T("Function updated."));
}