const char * gmVariable::AsString(gmMachine * a_machine, char * a_buffer, int a_len) const { switch(m_type) { case GM_NULL : _gmsnprintf(a_buffer, a_len, "null"); break; case GM_INT : _gmsnprintf(a_buffer, a_len, "%d", m_value.m_int); break; case GM_FLOAT : _gmsnprintf(a_buffer, a_len, "%g", m_value.m_float); break; case GM_STRING : return ((gmStringObject *) GM_MOBJECT(a_machine, m_value.m_ref))->GetString(); default: gmAsStringCallback asStringCallback = a_machine->GetUserAsStringCallback(m_type); if(asStringCallback) { asStringCallback((gmUserObject *) GM_MOBJECT(a_machine, m_value.m_ref), a_buffer, a_len ); } else { _gmsnprintf(a_buffer, a_len, "%s:0x%x", a_machine->GetTypeName(m_type), m_value.m_ref); } break; } return a_buffer; }
void gmMatrix3::AsString(gmUserObject *a_object, char *a_buffer, int a_bufferLen) { gmMat3Type *pNative = gmMatrix3::GetNative(a_object); if ( pNative == NULL ) { _gmsnprintf( a_buffer, a_bufferLen, "not a matrix3" ); return; } float fX = 0.f, fY = 0.f, fZ = 0.f; pNative->ExtractEulerXYZ(fX, fY, fZ); //Note '#' always display decimal place, 'g' display exponent if > precision or 4 _gmsnprintf(a_buffer, a_bufferLen, "(%#.8g, %#.8g, %#.8g)", fX, fY, fZ); }
const char * gmVariable::AsStringWithType(gmMachine * a_machine, char * a_buffer, int a_len) const { // Copy the type first _gmsnprintf(a_buffer, a_len, "%s: ", a_machine->GetTypeName(m_type)); // Update for used portion int usedLen = (int)strlen(a_buffer); char* newBufferPos = a_buffer + usedLen; int newLen = a_len - usedLen; if(newLen > 0) //Paranoid check some string buffer remaining { const char * str = AsString(a_machine, newBufferPos, newLen); if(str != newBufferPos) { // copy what we can... this is used for debug purposes so it doesnt matter if we chop some off strncpy(newBufferPos, str, newLen); } } return a_buffer; }
static void GM_CDECL AsString(gmUserObject* a_object, char* a_buffer, int a_bufferLen) { gmByteBuffer* buf = (gmByteBuffer*)a_object->m_user; _gmsnprintf(a_buffer, a_bufferLen, "ByteBuffer (%d)", buf->m_byteBuffer->length()); }