Squirrel

The programming language
Welcome to Squirrel Sign in | Join | Help
in Search

[SqPlus] SquirrelObject compare

Last post 05-15-2008, 1:59 AM by auron0. 2 replies.
Sort Posts: Previous Next
  •  05-12-2008, 9:01 PM 2506

    [SqPlus] SquirrelObject compare

    Hi,
    I've noticed that SquirrelObject doesn't contain a comparison operator so I was thinking of implementing the following code for easier object comparisons in C++. It makes use of sq_cmp to do the comparison.

    bool & SquirrelObject::operator ==(SquirrelObject &o)
    {
        bool cmp = false;
        int oldtop = sq_gettop(hSquirrelVM);
        sq_pushroottable(hSquirrelVM);
        sq_pushobject(hSquirrelVM, GetObjectHandle());
        sq_pushobject(hSquirrelVM, o.GetObjectHandle());
        if(sq_cmp(hSquirrelVM) == 0)
            cmp = true;
       
        sq_settop(hSquirrelVM, oldtop);
        return cmp;
    }


    Is there a reason why this feature wasn't included in the first place?
  •  05-13-2008, 7:55 AM 2507 in reply to 2506

    Re: [SqPlus] SquirrelObject compare

    Hello,

    That's a useul addition. I added the function to the SqPlus review version (see previous post)

    Regards
    // ATS.

  •  05-15-2008, 1:59 AM 2510 in reply to 2507

    Re: [SqPlus] SquirrelObject compare

    Great :)

    Another function that might be useful to add is ComparePointer.
    That way, users could specify whether that they just want to compare the reference pointer and not the value.

    bool ComparePointer( const SquirrelObject &o )
    {
        if( this->GetObjectHandle()._type == o.GetObjectHandle()._type )
            if( this->GetObjectHandle()._unVal.pUserPointer == o.GetObjectHandle()._unVal.pUserPointer )
                return true;

        return false;
    }


View as RSS news feed in XML
Powered by Community Server, by Telligent Systems