当前位置: 首页>>代码示例>>C++>>正文


C++ StackHandler::Return方法代码示例

本文整理汇总了C++中StackHandler::Return方法的典型用法代码示例。如果您正苦于以下问题:C++ StackHandler::Return方法的具体用法?C++ StackHandler::Return怎么用?C++ StackHandler::Return使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StackHandler的用法示例。


在下文中一共展示了StackHandler::Return方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setVar

static int setVar(StackHandler & sa,VarRef * vr,void * data) {
  if (vr->access & (VAR_ACCESS_READ_ONLY|VAR_ACCESS_CONSTANT)) {
    ScriptStringVar256 msg;
    const SQChar * el = sa.GetString(2);
    SCSNPRINTF(msg.s,sizeof(msg),_T("setVar(): Cannot write to constant: %s"),el);
#if defined( MONASQ )
    return sa.ThrowError(msg.s);
#else
    throw SquirrelError(msg.s);
#endif
  } // if
  switch (vr->type) {
  case TypeInfo<INT>::TypeID: {
    INT * val = (INT *)data; // Address
    if (val) {
      *val = sa.GetInt(3);
      return sa.Return(*val);
    } // if
    break;
  } // case
  case TypeInfo<FLOAT>::TypeID: {
    FLOAT * val = (FLOAT *)data; // Address
    if (val) {
      *val = sa.GetFloat(3);
      return sa.Return(*val);
    } // if
    break;
  } // case
  case TypeInfo<bool>::TypeID: {
    bool * val = (bool *)data; // Address
    if (val) {
      *val = sa.GetBool(3) ? true : false;
      return sa.Return(*val);
    } // if
    break;
  } // case
  case VAR_TYPE_INSTANCE: {
    HSQUIRRELVM v = sa.GetVMPtr();
    // vr->copyFunc is the LHS variable type: the RHS var's type is ClassType<>::type() (both point to ClassType<>::copy()).
    // src will be null if the LHS and RHS types don't match.
    SQUserPointer src = sa.GetInstanceUp(3,(SQUserPointer)vr->copyFunc); // Effectively performs: ClassType<>::type() == ClassType<>getCopyFunc().
#if defined( MONASQ )
    if (!src) return sa.ThrowError(_T("INSTANCE type assignment mismatch"));
#else
    if (!src) throw SquirrelError(_T("INSTANCE type assignment mismatch"));
#endif
    vr->copyFunc(data,src);
#if 0 // Return an instance on the stack (allocates memory)
    if (!CreateNativeClassInstance(sa.GetVMPtr(),vr->typeName,data,0)) { // data = address
      ScriptStringVar256 msg;
      SCSNPRINTF(msg.s,sizeof(msg),_T("getVar(): Could not create instance: %s"),vr->typeName);
      throw SquirrelError(msg.s);
    } // if
    return 1;
#else // Don't return on stack.
    return 0;
#endif
  }
  case TypeInfo<SQUserPointer>::TypeID: {
    ScriptStringVar256 msg;
    const SQChar * el = sa.GetString(2);
    SCSNPRINTF(msg.s,sizeof(msg),_T("setVar(): Cannot write to an SQUserPointer: %s"),el);
#if defined( MONASQ )
    return sa.ThrowError(msg.s);
#else
    throw SquirrelError(msg.s);
#endif
  } // case
  case TypeInfo<ScriptStringVarBase>::TypeID: {
    ScriptStringVarBase * val = (ScriptStringVarBase *)data; // Address
    if (val) {
      const SQChar * strVal = sa.GetString(3);
      if (strVal) {
        *val = strVal;
        return sa.Return(val->s);
      } // if
    } // if
    break;
  } // case
  } // switch
  return SQ_ERROR;
} // setVar
开发者ID:Hiroyuki-Nagata,项目名称:mona,代码行数:82,代码来源:SqPlus.cpp

示例2: setVar

static int setVar(StackHandler & sa,VarRef * vr,void * data) {
  if (vr->m_access & (VAR_ACCESS_READ_ONLY|VAR_ACCESS_CONSTANT)) {
    const SQChar * el = sa.GetString(2);
    SCSNPRINTF(g_msg_throw.s,sizeof(g_msg_throw),_SC("setVar(): Cannot write to constant: %s"),el);
    throw SquirrelError(g_msg_throw.s);
  } // if
  switch (vr->m_type) {
  case TypeInfo<INT>::TypeID: {
    INT * val = (INT *)data; // Address
    if (val) {
        INT v = sa.GetInt(3);
        // Support for different int sizes
        switch( vr->m_size ) {
          case 1: v = (*(char*)val = (char)v); break;  
          case 2: v = (*(short*)val = (short)v); break;  
#ifdef _SQ64
          case 4: v = (*(int*)val = (int)v); break;
#endif            
          default: *val = v;
       }
       return sa.Return(v);
    } // if
    break;
  } // case
  case TypeInfo<unsigned>::TypeID: {
	  unsigned * val = (unsigned *)data; // Address
	  if (val) {
		  *val = sa.GetInt(3);
		  return sa.Return(static_cast<INT>(*val));
	  } // if
	  break;
  } // case
  case TypeInfo<FLOAT>::TypeID: {
    FLOAT * val = (FLOAT *)data; // Address
    if (val) {
      *val = sa.GetFloat(3);
      return sa.Return(*val);
    } // if
    break;
  } // case
  case TypeInfo<bool>::TypeID: {
    bool * val = (bool *)data; // Address
    if (val) {
      *val = sa.GetBool(3) ? true : false;
      return sa.Return(*val);
    } // if
    break;
  } // case
  case VAR_TYPE_INSTANCE: {
    HSQUIRRELVM v = sa.GetVMPtr();
    SQUserPointer src = sa.GetInstanceUp(3,(SQUserPointer)vr->varType); // Effectively performs: ClassType<>::type() == ClassType<>().
    if (!src) {
      throw SquirrelError(_SC("INSTANCE type assignment mismatch"));
    }
    vr->varType->vgetCopyFunc()(data,src);
    return 0;
  }
  case TypeInfo<SQUserPointer>::TypeID: {
    const SQChar * el = sa.GetString(2);
    SCSNPRINTF(g_msg_throw.s,sizeof(g_msg_throw),_SC("setVar(): Cannot write to an SQUserPointer: %s"),el);
    throw SquirrelError(g_msg_throw.s);
  } // case
  case TypeInfo<ScriptStringVarBase>::TypeID: {
    ScriptStringVarBase * val = (ScriptStringVarBase *)data; // Address
    if (val) {
      const SQChar * strVal = sa.GetString(3);
      if (strVal) {
        *val = strVal;
        return sa.Return(val->s);
      } // if
    } // if
    break;
  } // case
#if defined(SQPLUS_SUPPORT_STD_STRING) && !defined(SQUNICODE)
  case TypeInfo<std::string>::TypeID: {
    std::string *val = (std::string*)data; // Address
    if (val) {
      const SQChar *strVal = sa.GetString(3);
      if (strVal) {
        *val = strVal;
        return sa.Return(val->c_str());
      } // if
   } // if
   break;
  } // case
#endif      
  } // switch
  return SQ_ERROR;
} // setVar
开发者ID:hamstah,项目名称:geogen,代码行数:89,代码来源:SqPlus.cpp

示例3: getVar

static int getVar(StackHandler & sa,VarRef * vr,void * data) {
  switch (vr->type) {
  case TypeInfo<INT>::TypeID: {
    if (!(vr->access & VAR_ACCESS_CONSTANT)) {
      INT * val = (INT *)data; // Address
      if (val) {
        return sa.Return(*val);
      } // if
    } else {
      INT * val = (INT *)&data; // Constant value
      return sa.Return(*val);
    } // if
    break;
  } // case
  case TypeInfo<FLOAT>::TypeID: {
    if (!(vr->access & VAR_ACCESS_CONSTANT)) {
      FLOAT * val = (FLOAT *)data; // Address
      if (val) {
        return sa.Return(*val);
      } // if
    } else {
      FLOAT * val = (FLOAT *)&data; // Constant value
      return sa.Return(*val);
    } // if
    break;
  } // case
  case TypeInfo<bool>::TypeID: {
    if (!(vr->access & VAR_ACCESS_CONSTANT)) {
      bool * val = (bool *)data; // Address
      if (val) {
        return sa.Return(*val);
      } // if
    } else {
      bool * val = (bool *)&data; // Constant value
      return sa.Return(*val);
    } // if
    break;
  } // case
  case VAR_TYPE_INSTANCE:
    if (!CreateNativeClassInstance(sa.GetVMPtr(),vr->typeName,data,0)) { // data = address. Allocates memory.
      ScriptStringVar256 msg;
      SCSNPRINTF(msg.s,sizeof(msg),_T("getVar(): Could not create instance: %s"),vr->typeName);
#if defined( MONASQ )
      return sa.ThrowError(msg.s);
#else
      throw SquirrelError(msg.s);
#endif
    } // if
    return 1;
  case TypeInfo<SQUserPointer>::TypeID: {
    return sa.Return(data); // The address of member variable, not the variable itself.
  } // case
  case TypeInfo<ScriptStringVarBase>::TypeID: {
    if (!(vr->access & VAR_ACCESS_CONSTANT)) {
      ScriptStringVarBase * val = (ScriptStringVarBase *)data; // Address
      if (val) {
        return sa.Return(val->s);
      } // if
    } else {
#if defined( MONASQ )
      return sa.ThrowError(_T("getVar(): Invalid type+access: 'ScriptStringVarBase' with VAR_ACCESS_CONSTANT (use VAR_ACCESS_READ_ONLY instead)"));
#else
      throw SquirrelError(_T("getVar(): Invalid type+access: 'ScriptStringVarBase' with VAR_ACCESS_CONSTANT (use VAR_ACCESS_READ_ONLY instead)"));
#endif
    } // if
    break;
  } // case
  case TypeInfo<const SQChar *>::TypeID: {
    if (!(vr->access & VAR_ACCESS_CONSTANT)) {
#if defined( MONASQ )
      return sa.ThrowError(_T("getVar(): Invalid type+access: 'const SQChar *' without VAR_ACCESS_CONSTANT"));
#else
      throw SquirrelError(_T("getVar(): Invalid type+access: 'const SQChar *' without VAR_ACCESS_CONSTANT"));
#endif
    } else {
      return sa.Return((const SQChar *)data); // Address
    } // if
    break;
  } // case
  } // switch
  return SQ_ERROR;
} // getVar
开发者ID:Hiroyuki-Nagata,项目名称:mona,代码行数:82,代码来源:SqPlus.cpp

示例4: getVar

static int getVar(StackHandler & sa,VarRef * vr,void * data) {
  switch (vr->m_type) {
  case TypeInfo<INT>::TypeID: {
    if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
      if (data) {
          INT v;
          // Support for different int sizes
          switch( vr->m_size ){
            case 1: v = *(char*)data; break;  
            case 2: v = *(short*)data; break;  
#ifdef _SQ64
            case 4: v = *(int*)data; break;
#endif            
            default: v = *(INT*)data;
          }
          return sa.Return(v);
      } // if
    } else {
      INT * val = (INT *)&data; // Constant value
      return sa.Return(*val);
    } // if
    break;
  } // case
  case TypeInfo<unsigned>::TypeID: {
	  if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
		  unsigned * val = (unsigned *)data; // Address
		  if (val){
            return sa.Return(static_cast<INT>(*val));
          }
	  } else {
		  unsigned * val = (unsigned *)&data; // Constant value
		  return sa.Return(static_cast<INT>(*val));
	  } // if
	  break;
  } // case
  case TypeInfo<FLOAT>::TypeID: {
    if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
      FLOAT * val = (FLOAT *)data; // Address
      if (val) {
        return sa.Return(*val);
      } // if
    } else {
      FLOAT * val = (FLOAT *)&data; // Constant value
      return sa.Return(*val);
    } // if
    break;
  } // case
  case TypeInfo<bool>::TypeID: {
    if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
      bool * val = (bool *)data; // Address
      if (val) {
        return sa.Return(*val);
      } // if
    } else {
      bool * val = (bool *)&data; // Constant value
      return sa.Return(*val);
    } // if
    break;
  } // case
  case VAR_TYPE_INSTANCE:
    if (!CreateNativeClassInstance(sa.GetVMPtr(),vr->varType->GetTypeName(),data,0)) { // data = address. Allocates memory.
      SCSNPRINTF(g_msg_throw.s,sizeof(g_msg_throw),_SC("getVar(): Could not create instance: %s"),vr->varType->GetTypeName());
      throw SquirrelError(g_msg_throw.s);
    } // if
    return 1;
  case TypeInfo<SQUserPointer>::TypeID: 
    return sa.Return(data); // The address of member variable, not the variable itself.
  case TypeInfo<ScriptStringVarBase>::TypeID: {
    if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
      ScriptStringVarBase * val = (ScriptStringVarBase *)data; // Address
      if (val) {
        return sa.Return(val->s);
      } // if
    } else {
      throw SquirrelError(_SC("getVar(): Invalid type+access: 'ScriptStringVarBase' with VAR_ACCESS_CONSTANT (use VAR_ACCESS_READ_ONLY instead)"));
    }
    break;
  } // case
  case TypeInfo<const SQChar *>::TypeID: {
    if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
      if( vr->m_access==VAR_ACCESS_READ_WRITE )
        throw SquirrelError(_SC("getVar(): Invalid type+access: 'const SQChar *' without VAR_ACCESS_CONSTANT"));
      // It is OK to read from a SQChar* if requested
      return sa.Return(*(const SQChar **)data); // Address
    } else {
      return sa.Return((const SQChar *)data); // Address
    }
    break;
  } // case
#ifdef SQPLUS_SUPPORT_STD_STRING
  case TypeInfo<std::string>::TypeID: {
    if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
      std::string *val = (std::string *)data; // Address
      if (val) {
        return sa.Return(val->c_str());
      }
    } else {
      throw SquirrelError(_SC("getVar(): Invalid type+access: 'std::string' with VAR_ACCESS_CONSTANT (use VAR_ACCESS_READ_ONLY instead)"));
    }
    break;
//.........这里部分代码省略.........
开发者ID:hamstah,项目名称:geogen,代码行数:101,代码来源:SqPlus.cpp


注:本文中的StackHandler::Return方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。