Re: [Circle] Safe Character extraction.

From: George Greer (greerga@circlemud.org)
Date: 06/29/00


On Thu, 29 Jun 2000, Patrick Dughi wrote:

>        Basically, a pair of set/accessor functions for each character
>part, based on idnum lookup?  Sounds a bit annoying.  Say I want to access
>the sex.  ch->player->sex (or ch.player->sex depending on how you load up
>the file).  My function should only require a unique player number.  It
>should locate the character pointer, verify it's existance, verify the
>player structure existance, and then return the sex.  If there are any
>problems, it will have to error out - in this case, returning a negative
>number.  This is reasonable for this single function, but writing specific
>case functions for each member could end up to be time consuming.  There
>should be a more easily extendable method.

Templates, Perl's AUTOLOAD, or judicious use of the preprocessor.

You may be wondering about the Perl AUTOLOAD I mentioned.  Well, I'd like
to embed Perl in CircleMUD.  Then you don't have to worry about scripting
limitations.  You'll have to worry about security if you give it to people
you don't trust and fail it lock it down properly, but the possibilities
are great.  I had planned on writing a few "native" C drivers for SQL
databases and then fudging the rest through Perl's DBI.  That way, even if
there isn't a driver written specifically for the database, you can still
use it if Perl supports it, albeit slower.

>        Perl-like hash tables? Some sort of structure registar for
>player/mob structs?  There should be some way to make it as simple as
>possible, say one line of text, and the rest should be automatic.

Possibly.

int get_sex(ID)
{
  struct char_data *ch = get_ch_by_id(ID);
  return ch ? ch->sex : -1;
}

If you wanted it to be simple and tedious.  For better results, use the
offset into the structure by field and build a table that can be referred
to for the values.  Then one function takes care of the information.  It'd
need a bit of magic to do so.

>        I'll see if I can't write a general way using a sort of named
>lookup thing... get_value(chidnum,"gender"); or something..

Should be possible though you may end up with casting if you do it
differently.

--
George Greer
greerga@circlemud.org


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



This archive was generated by hypermail 2b30 : 04/10/01 PDT