void Printer::PrintValue(std::string *result, Sqrat::Object object) { if (object.IsNull()) { result->append("null"); } else { if (object.GetType() == OT_TABLE) { PrintTable(result, object.Cast<Sqrat::Table>()); } else if (object.GetType() == OT_ARRAY) { PrintArray(result, object.Cast<Sqrat::Array>()); } else if (object.GetType() == OT_INTEGER) { Util::SafeFormat(mPrintBuffer, sizeof(mPrintBuffer), "%lu", object.Cast<unsigned long>()); result->append(mPrintBuffer); } else if (object.GetType() == OT_STRING) { result->append("\"" + object.Cast<std::string>() + "\""); } else if (object.GetType() == OT_BOOL) { result->append(object.Cast<bool>() ? "true" : "false"); } else if (object.GetType() == OT_FLOAT) { Util::SafeFormat(mPrintBuffer, sizeof(mPrintBuffer), "%f", object.Cast<double>()); result->append(mPrintBuffer); } else { Vector3 *vec3 = object.Cast<Vector3*>(); if (vec3 != NULL) { Util::SafeFormat(mPrintBuffer, sizeof(mPrintBuffer), "Vector3(%f,%f,%f)", vec3->mX, vec3->mY, vec3->mZ); result->append(mPrintBuffer); } } } }
void myFunc() { //LogMsg("This is a test from squirrell"); Sqrat::Object slotVal = Sqrat::RootTable().GetSlot("myVal"); if (slotVal.IsNull() == false) { //LogMsg("%d", slotVal.Cast<int>()); } }
Json::Value JsonPrinter::PrintValue(Sqrat::Object object) { if(!object.IsNull()) { if(object.GetType() == OT_TABLE) { Json::Value v; PrintTable(v, object.Cast<Sqrat::Table>()); return v; } else if(object.GetType() == OT_ARRAY) { Json::Value v(Json::arrayValue); PrintArray(v, object.Cast<Sqrat::Array>()); return v; } else if(object.GetType() == OT_INTEGER) { return Json::UInt64(object.Cast<unsigned long>()); } else if(object.GetType() == OT_STRING) { return Json::Value(object.Cast<std::string>()); } else if(object.GetType() == OT_BOOL) { return Json::Value(object.Cast<bool>()); } else if(object.GetType() == OT_FLOAT) { return Json::Value(object.Cast<double>()); } else { Vector3 *vec3 = object.Cast<Vector3*>(); if(vec3 != NULL) { Json::Value v3; v3["x"] = vec3->mX; v3["y"] = vec3->mY; v3["z"] = vec3->mZ; return v3; } } } Json::Value v; return v; }