Squirrel

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

SqPlus: Match() behavior in DECLARE_INSTANCE_TYPE_NAME_ macro

Last post 06-28-2006, 8:59 AM by Katsuaki Kawachi. 2 replies.
Sort Posts: Previous Next
  •  06-27-2006, 8:04 AM 962

    SqPlus: Match() behavior in DECLARE_INSTANCE_TYPE_NAME_ macro

    I'm using SqPlus in SQUIRREL2_1_0_sqplus_19.

    The DECLARE_INSTANCE_TYPE_NAME_ macro in sqplus.h and SqPlusConst.h
    creates the helper functions "bool Match()" for my C++ class, but these functions don't
    seem to return false.

    It is because that the GetInstance() function used in the generated Match() functions
    doesn't return false but throws exception when the given argument type is invalid.

    It would be helpful for me to make the function not to throw exception
    as follows:

    1. Add MatchInstance() function in sqplus.h

    // Match an instance of type T from the stack at idx (for function calls).
    template<typename T>
    bool MatchInstance(HSQUIRRELVM v,SQInteger idx) {
      SQUserPointer up=0;
      sq_getinstanceup(v,idx,&up,ClassType<T>::type());
      return (up != NULL);
    } // MatchInstance

    2. Use MatchInstance(v, idx) instead of "GetInstance<TYPE>(v,idx) != NULL"
       in DECLARE_INSTANCE_TYPE_NAME macro in sqplus.h and SqPlusConst.h.  

    It works well for me.  How about this change?
  •  06-27-2006, 10:27 AM 963 in reply to 962

    Re: SqPlus: Match() behavior in DECLARE_INSTANCE_TYPE_NAME_ macro

    Added to release 20, with appropriate changes to Match() and Get():


    template<typename T,bool ExceptionOnError>
    T * GetInstance(HSQUIRRELVM v,SQInteger idx) {
      SQUserPointer up=0;
      sq_getinstanceup(v,idx,&up,ClassType<T>::type());
      if (ExceptionOnError) { // This code block should be compiled out when ExceptionOnError is false. In any case, the compiler should not generate a test condition (include or exclude the enclosed code block).
        if (!up) throw SquirrelError(_T("GetInstance: Invalid argument type"));
      } // if
      return (T *)up;
    } // GetInstance


    http://www.brightland.com/sq/SQUIRREL2_1_0_sqplus_20.zip
  •  06-28-2006, 8:59 AM 964 in reply to 963

    Re: SqPlus: Match() behavior in DECLARE_INSTANCE_TYPE_NAME_ macro

    Thank you!
    :-)
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems