Re: [ Idea ] actf() ?!?!

From: Erwin S. Andreasen (erwin@PIP.DKNET.DK)
Date: 10/08/97


On Wed, 8 Oct 1997, Daniel Koepke wrote:

> -+ Would it make sense? That is writing actf()? :)
>
> No, it'd not make sense and it'd be difficult.  You see, for an
> "xxxf()" function to work, the format string has to be last.
> That means,
>
>   act(char *, bool, char_data *, void *, void *, int);
>
> would have to be changed to
>
>   actf(bool, char_data *, void *, void *, int, char *, ...);

What makes you thing this? The only requirement variadic functions have is
that they take at least one non-optional non-register argument.

If you really wanted to make an actf() function which takes a variable
number of arguments, it would be pretty straightforward, once you master
the use of va_xxx macros that are used to access optional arguments. You
could imagine a format like this:

actf ("You hit $n, making $m BLEED!.", TO_CHAR, ch, victim, victim);

Function prototype would be: void actf (const char *fmt, int to, void
*target, ...);

The function would start by looking at the the "to" field to find out if
the target was a character, a room, eveyone except this character or
something else.

Then, the format string would be examined: when encountering $n, the
function would call va_arg to pull one CHAR_DATA * from the variable
arguments. When encountering the $m, the function would pull another.

This has the advantage of allowing any number of actors in the string. Of
course, since current act() seldom has need of more than 3 total, the
advantage is small.

Diku II uses a similar method. They however, use numbered arguments as far
as I can see, so you refer e.g. to "$1n" to mean: take the first variable
argument passsed, interpret it as a character and show its name. Using
that system, the above would be something like:

actf ("You hit $1n, making $1m bleed!", TO_CHAR, ch, victim);

I think, I do not have the source - the function (DikuII being closer
to LP in style, i.e. softcoded) is documented at their web site,
http://www.valhalla.com (?).

Finally, Sapphire, Joseph(?) Grantz's (?) MUD server employs a similar
method. He has mase the source available; It's possible you can find it by
looking at www.game.org - I think it's there. I do not recall the exact
method he uses, but he posted his act() code to the MERC Mailing List a
while ago.

SEE ALSO: man stdarg.

 =============================================================================
Erwin Andreasen   Herlev, Denmark <erwin@pip.dknet.dk>  UNIX System Programmer
<URL:http://pip.dknet.dk/~erwin/>         <*>           (not speaking for) DDE
 =============================================================================


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST