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


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

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


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


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