%+ is the number of arguments to the current function
authorAri Johnson <ari@cobramush.org>
Wed, 21 Feb 2007 00:45:13 +0000 (00:45 +0000)
committerAri Johnson <ari@cobramush.org>
Wed, 21 Feb 2007 00:45:13 +0000 (00:45 +0000)
game/txt/hlp/cobratop.hlp
hdrs/mushtype.h
src/funufun.c
src/parse.c

index 82f767a2d49926c67aa842c100aa95cbff74366a..d21ed1c804643ebc5d2d5c05ce2d489311297334 100644 (file)
@@ -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)
index efd190180537a2d670fdab79deeadd731b161e50..4fcff6a19d9ff4eff94e8d6655649ea219daae00 100644 (file)
@@ -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 */
index 15321f0b7a91772cb5688aa5285b923f07581ae9..b816d9a2b08e012648fd3ae77c7a1455511be3f0 100644 (file)
@@ -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 */
index 0fab687a75996c0b44872d4b224a672d4f4228f9..f99957ecf55ecbd414d7c4c56fb5ff983b2bf7c5 100644 (file)
@@ -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;