From c166e3f606d72f504f6a3f8ce46711c706beb930 Mon Sep 17 00:00:00 2001 From: Ari Johnson Date: Wed, 21 Feb 2007 00:45:13 +0000 Subject: [PATCH] %+ is the number of arguments to the current function --- game/txt/hlp/cobratop.hlp | 1 + hdrs/mushtype.h | 1 + src/funufun.c | 7 +++++++ src/parse.c | 11 +++++++++++ 4 files changed, 20 insertions(+) diff --git a/game/txt/hlp/cobratop.hlp b/game/txt/hlp/cobratop.hlp index 82f767a..d21ed1c 100644 --- a/game/txt/hlp/cobratop.hlp +++ b/game/txt/hlp/cobratop.hlp @@ -1582,6 +1582,7 @@ Continued in 'help regexp classes2' %L = the dbref of the ENACTOR's location. %c = text of the last command, _before_ evaluation. %? = The current function invocation and depth counts. + %+ = The number of arguments passed to the current function. %qN = the equivalent of r(N), a register set by a setq() function. (continued in help substitutions4) diff --git a/hdrs/mushtype.h b/hdrs/mushtype.h index efd1901..4fcff6a 100644 --- a/hdrs/mushtype.h +++ b/hdrs/mushtype.h @@ -87,6 +87,7 @@ struct pe_info { int nest_depth; /**< Depth of function nesting, for DEBUG */ int call_depth; /**< Function call counter */ Debug_Info *debug_strings; /**< DEBUG infromation */ + int arg_count; /**< Number of arguments passed to function */ }; /* new attribute foo */ diff --git a/src/funufun.c b/src/funufun.c index 15321f0..b816d9a 100644 --- a/src/funufun.c +++ b/src/funufun.c @@ -113,6 +113,7 @@ do_userfn(char *buff, char **bp, dbref obj, ATTR *attrib, int nargs, char *tbuf; char const *tp; int pe_flags = PE_DEFAULT; + int old_args; /* save our stack */ for (j = 0; j < 10; j++) @@ -125,6 +126,10 @@ do_userfn(char *buff, char **bp, dbref obj, ATTR *attrib, int nargs, global_eval_context.wenv[j] = args[j]; for (; j < 10; j++) global_eval_context.wenv[j] = NULL; + if (pe_info) { + old_args = pe_info->arg_count; + pe_info->arg_count = nargs; + } tp = tbuf = safe_atr_value(attrib); if (attrib->flags & AF_DEBUG) @@ -136,6 +141,8 @@ do_userfn(char *buff, char **bp, dbref obj, ATTR *attrib, int nargs, /* restore the stack */ for (j = 0; j < 10; j++) global_eval_context.wenv[j] = tptr[j]; + if (pe_info) + pe_info->arg_count = old_args; } /* ARGSUSED */ diff --git a/src/parse.c b/src/parse.c index 0fab687..f99957e 100644 --- a/src/parse.c +++ b/src/parse.c @@ -504,6 +504,7 @@ process_expression(char *buff, char **bp, char const **str, pe_info->nest_depth = 0; pe_info->call_depth = 0; pe_info->debug_strings = NULL; + pe_info->arg_count = 0; } else { old_iter_limit = -1; } @@ -750,6 +751,12 @@ process_expression(char *buff, char **bp, char const **str, case '~': /* enactor accented name */ safe_str(accented_name(enactor), buff, bp); break; + case '+': /* argument count */ + if (pe_info) + safe_integer(pe_info->arg_count, buff, bp); + else + safe_integer(0, buff, bp); + break; case '0': case '1': case '2': @@ -1230,10 +1237,14 @@ process_expression(char *buff, char **bp, char const **str, global_fun_recursions++; pe_info->fun_depth++; if (fp->flags & FN_BUILTIN) { + int old_nfargs; global_fun_invocations++; pe_info->fun_invocations++; + old_nfargs = pe_info->arg_count; + pe_info->arg_count = nfargs; fp->where.fun(fp, buff, bp, nfargs, fargs, arglens, executor, caller, enactor, fp->name, pe_info); + pe_info->arg_count = old_nfargs; if (fp->flags & FN_LOGARGS) { char logstr[BUFFER_LEN]; char *logp; -- 2.30.2