[MUD-Dev] New Here

MIKE MacMartin mike at igs.net
Sat Jun 21 08:47:28 New Zealand Standard Time 2003


On 20 Jun 2003 13:13:04 -0700
Mike  <szii at sziisoft.com> wrote:

> Welcome to the list.  =)

Thanks.

> Now on to your question...

> This may be a style thing, but...

> Do this.  Change your while from

>     while ((pos = fmt.find('$', pos + 1)), pos != string::npos) {

> to
>     while (pos != string::npos) { // string::npos is -1
>       pos = fmt.find('$',pos + 1);
>       if (pos != string:: npos) {
>         // work the string in here
>       }
>     }

Actually, my fix was in my CSocket::operator >>  ... I made my socket class
work like iostreams, since, for all intents and purposes, that's what they
are.

I had it looking something like:

  CSocket& CSocket::operator >>(string& text) {
    // appropriate read call into a buffer, assigning to text
    text.erase(text.length() - 1); // to get rid of \n
    return *this; // to chain it like cout/cin etc.
  }

If you pay attention to that code, you'll notice that it's
incomplete... what I really wanted was to get rid of newline chars
... but sometimes I get a \r\n ... and this just gets rid of the
newline.

Brace yourself: this means that it goes to the start of the line
with a character that there's no way I'd be able to get outputted.
I was drawn to this (correct) thought due to the extra characters in
the string's size.

The fix is just a simple change:

  while (text[text.length() -1] == '\n' || text[text.length() - 1] == '\r')
    text.erase(text.length() - 1);

Also, on the subject of scripting languages, I've embedded TCL, but
I'm thinking Ruby might be a better choice (due to the obvious
object-oriented nature of an RPG) but I've never used it.  Any
thoughts?

Also, I'm expecting people to be designing game systems over top of
my library.  So, I've gone and made a superclass "Functor" for the
object, which just currently makes sure they implement an
operator().

Functors, for those of you who don't know, are C++ objects that
basically look like:

  struct Functor: binary_function<CCharacter&, vector<string>&, bool> {
    virtual bool operator()(CCharacter& ch, vector<string>& args) {
      ch.descriptor() << "Plain functor!  Bug!";
      return true;
    }
  };

I'm thinking I may want to extend it with this:

  struct Functor: binary_function<CCharacter&, vector<string>&, bool> {
    // operator()
    int tclAPI(/* TCL args ... can't remember them */) {
      // fetch the character
      // break up the TCL args I get from one string to a vector<strings>
      return (*this)(ch, args)? TCL_OK : TCL_ERR;
    }
  };

and mandating that in the constructor for the functor (odd thinking
of functions having constructors...) having a

  Game::getGame().registerTCL("name", tclAPI);

... would that work?  It would seem to be the best solution, as it
would almost automatically provide a TCL API for everything
implemented.


> -Mike
MIKE (yup, another mike)
--
Beware the JabberOrk
_______________________________________________
MUD-Dev mailing list
MUD-Dev at kanga.nu
https://www.kanga.nu/lists/listinfo/mud-dev



More information about the MUD-Dev mailing list