Status parseNumberFromStringWithBase( const StringData& stringValue, int base, NumberType* result) { typedef ::std::numeric_limits<NumberType> limits; if (base == 1 || base < 0 || base > 36) return Status(ErrorCodes::BadValue, "Invalid base", 0); bool isNegative = false; StringData str = _extractBase(_extractSign(stringValue, &isNegative), base, &base); if (str.empty()) return Status(ErrorCodes::FailedToParse, "No digits"); NumberType n(0); if (isNegative) { if (limits::is_signed) { for (size_t i = 0; i < str.size(); ++i) { NumberType digitValue = NumberType(_digitValue(str[i])); if (int(digitValue) >= base) return Status(ErrorCodes::FailedToParse, "Bad digit"); // MSVC: warning C4146: unary minus operator applied to unsigned type, result still unsigned // This code is statically known to be dead when NumberType is unsigned, so the warning is not real #pragma warning(push) #pragma warning(disable:4146) if ((NumberType(limits::min() / base) > n) || ((limits::min() - NumberType(n * base)) > -digitValue)) { #pragma warning(pop) return Status(ErrorCodes::FailedToParse, "Underflow"); } n *= NumberType(base); n -= NumberType(digitValue); } } else { return Status(ErrorCodes::FailedToParse, "Negative value"); } } else { for (size_t i = 0; i < str.size(); ++i) { NumberType digitValue = NumberType(_digitValue(str[i])); if (int(digitValue) >= base) return Status(ErrorCodes::FailedToParse, "Bad digit"); if ((NumberType(limits::max() / base) < n) || (NumberType(limits::max() - n * base) < digitValue)) { return Status(ErrorCodes::FailedToParse, "Overflow"); } n *= NumberType(base); n += NumberType(digitValue); } } *result = n; return Status::OK(); }
AnyType::operator NumberType() { if (type == TypeNumber) return NumberType(value.num); else if (type == TypeFloat) return NumberType(value.numf); else throw InvalidConversionException(type, TypeNumber); }
Status parseNumberFromStringWithBase( const StringData& stringValue, int base, NumberType* result) { typedef ::std::numeric_limits<NumberType> limits; if (base == 1 || base < 0 || base > 36) return Status(ErrorCodes::BadValue, "Invalid base", 0); if (stringValue.size() == 0) return Status(ErrorCodes::FailedToParse, "Empty string"); bool isNegative = false; StringData str = _extractBase(_extractSign(stringValue, &isNegative), base, &base); NumberType n(0); if (isNegative) { if (limits::is_signed) { for (size_t i = 0; i < str.size(); ++i) { NumberType digitValue = NumberType(_digitValue(str[i])); if (int(digitValue) >= base) return Status(ErrorCodes::FailedToParse, "Bad digit"); if ((NumberType(limits::min() / base) > n) || ((limits::min() - NumberType(n * base)) > -digitValue)) { return Status(ErrorCodes::FailedToParse, "Underflow"); } n *= NumberType(base); n -= NumberType(digitValue); } } else { return Status(ErrorCodes::FailedToParse, "Negative value"); } } else { for (size_t i = 0; i < str.size(); ++i) { NumberType digitValue = NumberType(_digitValue(str[i])); if (int(digitValue) >= base) return Status(ErrorCodes::FailedToParse, "Bad digit"); if ((NumberType(limits::max() / base) < n) || (NumberType(limits::max() - n * base) < digitValue)) { return Status(ErrorCodes::FailedToParse, "Overflow"); } n *= NumberType(base); n += NumberType(digitValue); } } *result = n; return Status::OK(); }
bool DeleteUser(UserManager *panel,bool selection) { bool res=false; CFarPanelSelection sp((HANDLE)panel,selection); if(sp.Number()) { TCHAR warning[TINY_BUFFER]; if(sp.Number()==1) { TCHAR Truncated[MAX_PATH]; _tcscpy(Truncated,sp[0].FileName); FSF.TruncPathStr(Truncated,50); FSF.sprintf(warning,GetMsg(mDelOne),Truncated); } else FSF.sprintf(warning,GetMsg(mDelUserN+NumberType(sp.Number())),sp.Number()); const TCHAR *MsgItems[]={GetMsg(mButtonDelete),warning,GetMsg(mButtonDelete),GetMsg(mButtonCancel)}; if(!Info.Message(&MainGuid,&DelUserMessageGuid,0,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),2)) { res=true; for(int i=0;i<sp.Number();i++) { if(sp[i].UserData.FreeData) NetUserDel((panel->global)?(panel->domain):(panel->computer_ptr),GetWideNameFromUserData(sp[i].UserData.Data)); } } } return res; }
AnyType TPTScriptInterface::tptS_delete(std::deque<std::string> * words) { //Arguments from stack AnyType partRef = eval(words); Simulation * sim = m->GetSimulation(); if(partRef.GetType() == TypePoint) { ui::Point deletePoint = ((PointType)partRef).Value(); if(deletePoint.X<0 || deletePoint.Y<0 || deletePoint.Y >= YRES || deletePoint.X >= XRES) throw GeneralException("Invalid position"); sim->delete_part(deletePoint.X, deletePoint.Y); } else if(partRef.GetType() == TypeNumber) { int partIndex = ((NumberType)partRef).Value(); if(partIndex < 0 || partIndex >= NPART) throw GeneralException("Invalid particle index"); sim->kill_part(partIndex); } else throw GeneralException("Invalid particle reference"); return NumberType(0); }
AnyType TPTScriptInterface::eval(std::deque<std::string> * words) { if(words->size() < 1) return AnyType(TypeNull, NULL); std::string word = words->front(); words->pop_front(); char * rawWord = (char *)word.c_str(); ValueType wordType = testType(word); switch(wordType) { case TypeFunction: if(word == "set") return tptS_set(words); else if(word == "create") return tptS_create(words); else if(word == "delete" || word == "kill") return tptS_delete(words); else if(word == "load") return tptS_load(words); else if(word == "reset") return tptS_reset(words); else if(word == "bubble") return tptS_bubble(words); break; case TypeNumber: return NumberType(atoi(rawWord)); case TypePoint: { int pointX, pointY; sscanf(rawWord, "%d,%d", &pointX, &pointY); return PointType(pointX, pointY); } case TypeString: return StringType(word); } }
AnyType::operator NumberType() { if(type != TypeNumber) throw InvalidConversionException(type, TypeNumber); else return NumberType((int)value); }
AnyType TPTScriptInterface::tptS_create(std::deque<std::string> * words) { //Arguments from stack AnyType createType = eval(words); PointType position = eval(words); Simulation * sim = m->GetSimulation(); int type; if(createType.GetType() == TypeNumber) type = ((NumberType)createType).Value(); else if(createType.GetType() == TypeString) type = GetParticleType(((StringType)createType).Value()); else throw GeneralException("Invalid type"); if(type == -1) throw GeneralException("Invalid particle type"); ui::Point tempPoint = position.Value(); if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES) throw GeneralException("Invalid position"); int returnValue = sim->create_part(-1, tempPoint.X, tempPoint.Y, type); return NumberType(returnValue); }
AnyType TPTScriptInterface::tptS_bubble(std::deque<std::string> * words) { //Arguments from stack PointType bubblePosA = eval(words); ui::Point bubblePos = bubblePosA.Value(); if(bubblePos.X<0 || bubblePos.Y<0 || bubblePos.Y >= YRES || bubblePos.X >= XRES) throw GeneralException("Invalid position"); Simulation * sim = m->GetSimulation(); int first, rem1, rem2; first = sim->create_part(-1, bubblePos.X+18, bubblePos.Y, PT_SOAP); rem1 = first; for (int i = 1; i<=30; i++) { rem2 = sim->create_part(-1, bubblePos.X+18*cosf(i/5.0), bubblePos.Y+18*sinf(i/5.0), PT_SOAP); sim->parts[rem1].ctype = 7; sim->parts[rem1].tmp = rem2; sim->parts[rem2].tmp2 = rem1; rem1 = rem2; } sim->parts[rem1].ctype = 7; sim->parts[rem1].tmp = first; sim->parts[first].tmp2 = rem1; sim->parts[first].ctype = 7; return NumberType(0); }
const LuaValue& LuaTable::getINext(LuaValue& k) const { if (k.isTypeOf(LVT_Nil)) { if (!m_vec.empty()) { k = LuaValue(NumberType(1)); return m_vec.front(); } return LuaValue::NIL; } else { int idx = (int)k.getNumber(); if (idx >= 0 && idx < (int)m_vec.size()) { k = LuaValue(NumberType(idx + 1)); return m_vec[idx]; } k = LuaValue::NIL; return LuaValue::NIL; } }
AnyType TPTScriptInterface::tptS_load(std::deque<std::string> * words) { //Arguments from stack NumberType saveID = eval(words); c->OpenSavePreview(saveID.Value(), 0); return NumberType(0); }
bool DeleteShare(UserManager *panel,bool selection) { bool res=false; CFarPanelSelection sp((HANDLE)panel,selection); if(sp.Number()) { TCHAR warning[TINY_BUFFER]; if(sp.Number()==1) { TCHAR Truncated[MAX_PATH]; _tcscpy(Truncated,sp[0].FileName); FSF.TruncPathStr(Truncated,50); FSF.sprintf(warning,GetMsg(mDelOne),Truncated); } else FSF.sprintf(warning,GetMsg(mDelShareN+NumberType(sp.Number())),sp.Number()); const TCHAR *MsgItems[]={GetMsg(mButtonDelete),warning,GetMsg(mButtonDelete),GetMsg(mButtonCancel)}; if(!Info.Message(&MainGuid,&DelShareMessageGuid,0,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),2)) { res=true; for(int i=0;i<sp.Number();i++) if(panel->level==levelPrinterShared) { HANDLE printer; PRINTER_DEFAULTSW defaults; PRINTER_INFO_2W *data=NULL; memset(&defaults,0,sizeof(defaults)); defaults.DesiredAccess=PRINTER_ALL_ACCESS; if(OpenPrinterW(panel->hostfile,&printer,&defaults)) { DWORD Needed; if(!GetPrinterW(printer,2,NULL,0,&Needed)) { if(GetLastError()==ERROR_INSUFFICIENT_BUFFER) { data=(PRINTER_INFO_2W *)malloc(Needed); if(data) { if(GetPrinterW(printer,2,(PBYTE)data,Needed,&Needed)) { data->Attributes&=~PRINTER_ATTRIBUTE_SHARED; if(SetPrinterW(printer,2,(PBYTE)data,0)) res=true; } free(data); data=NULL; } } } ClosePrinter(printer); } } else if(sp[i].UserData.FreeData) { NetShareDel(panel->computer_ptr,GetWideNameFromUserData(sp[i].UserData.Data),0); } } } return res; }
static void buildin_select(const vector<LuaValue>& args, vector<LuaValue>& rets) { auto &index = args[0]; if (index.isTypeOf(LVT_String) && index.toString() == "#") { rets.push_back(LuaValue(NumberType(args.size() - 1))); } else if (index.isTypeOf(LVT_Number)) { for (int i = (int)index.getNumber(); i < (int)args.size(); ++i) { rets.push_back(args[i]); } } else ASSERT(0); }
AnyType TPTScriptInterface::tptS_reset(std::deque<std::string> * words) { //Arguments from stack StringType reset = eval(words); std::string resetStr = reset.Value(); Simulation * sim = m->GetSimulation(); if (resetStr == "pressure") { for (int nx = 0; nx < XRES/CELL; nx++) for (int ny = 0; ny < YRES/CELL; ny++) { sim->air->pv[ny][nx] = 0; } } else if (resetStr == "velocity") { for (int nx = 0; nx < XRES/CELL; nx++) for (int ny = 0; ny < YRES/CELL; ny++) { sim->air->vx[ny][nx] = 0; sim->air->vy[ny][nx] = 0; } } else if (resetStr == "sparks") { for (int i = 0; i < NPART; i++) { if (sim->parts[i].type == PT_SPRK) { sim->parts[i].type = sim->parts[i].ctype; sim->parts[i].life = 4; } } } else if (resetStr == "temp") { for (int i = 0; i < NPART; i++) { if (sim->parts[i].type) { sim->parts[i].temp = sim->elements[sim->parts[i].type].Temperature; } } } else { throw GeneralException("Unknown reset command"); } return NumberType(0); }
AnyType TPTScriptInterface::tptS_load(std::deque<std::string> * words) { //Arguments from stack NumberType saveID = eval(words); if (saveID.Value() > 0) { c->OpenSavePreview(saveID.Value(), 0, false); return NumberType(0); } else throw GeneralException("Invalid save ID"); }
Tuplet::Tuplet(Score* s) : DurationElement(s) { setFlags(ElementFlag::MOVABLE | ElementFlag::SELECTABLE); _direction = score()->style(StyleIdx::tupletDirection).value<Direction>(); _numberType = NumberType(score()->style(StyleIdx::tupletNumberType).toInt()); _bracketType = BracketType(score()->style(StyleIdx::tupletBracketType).toInt()); _ratio = Fraction(1, 1); _number = 0; _hasBracket = false; _isUp = true; }
const LuaValue& LuaTable::getNext(LuaValue& k) const { if (k.isTypeOf(LVT_Nil)) { if (!m_vec.empty()) { k = LuaValue(NumberType(1)); return m_vec.front(); } if (!m_hashTable.empty()) { auto iter = m_hashTable.begin(); k = iter->first; return iter->second; } } else { if (k.isTypeOf(LVT_Number)) { int idx = (int)k.getNumber(); if (idx >= 0 && idx < (int)m_vec.size()) { k = LuaValue(NumberType(idx + 1)); return m_vec[idx]; } if (idx == (int)m_vec.size() && !m_hashTable.empty()) { auto iter = m_hashTable.begin(); k = iter->first; return iter->second; } } auto iter = m_hashTable.find(k); if (iter != m_hashTable.end()) { ++iter; if (iter != m_hashTable.end()) { k = iter->first; return iter->second; } } } k = LuaValue::NIL; return LuaValue::NIL; }
AnyType TPTScriptInterface::eval(std::deque<String> * words) { if(words->size() < 1) return AnyType(TypeNull, ValueValue()); String word = words->front(); words->pop_front(); ValueType wordType = testType(word); switch(wordType) { case TypeFunction: if(word == "set") return tptS_set(words); else if(word == "create") return tptS_create(words); else if(word == "delete" || word == "kill") return tptS_delete(words); else if(word == "load") return tptS_load(words); else if(word == "reset") return tptS_reset(words); else if(word == "bubble") return tptS_bubble(words); else if(word == "quit") return tptS_quit(words); break; case TypeNumber: return NumberType(parseNumber(word)); case TypeFloat: return FloatType(atof(word.ToUtf8().c_str())); case TypePoint: { int x, y; if(String::Split comma = word.SplitNumber(x)) if(comma.After().BeginsWith(",")) if(comma.After().Substr(1).SplitNumber(y)) return PointType(x, y); return PointType(0, 0); } case TypeString: return StringType(word); default: break; } return StringType(word); }
bool DeleteRightUsers(UserManager *panel,bool selection) { bool res=false; CFarPanelSelection sp((HANDLE)panel,selection); if(sp.Number()) { TCHAR warning[TINY_BUFFER]; if(sp.Number()==1) { TCHAR Truncated[MAX_PATH]; _tcscpy(Truncated,sp[0].FileName); FSF.TruncPathStr(Truncated,50); FSF.sprintf(warning,GetMsg(mDelOne),Truncated); } else FSF.sprintf(warning,GetMsg(mDelUserN+NumberType(sp.Number())),sp.Number()); const TCHAR *MsgItems[]={GetMsg(mButtonDelete),warning,GetMsg(mButtonDelete),GetMsg(mButtonCancel)}; if(!Info.Message(&MainGuid,&DelUserMessageGuid,0,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),2)) { res=true; LSA_HANDLE PolicyHandle; PolicyHandle=GetPolicyHandle(panel->computer); if(PolicyHandle) { for(int i=0;i<sp.Number();i++) { if(sp[i].UserData.FreeData) { LSA_UNICODE_STRING RightName; RightName.Buffer=panel->nonfixed; RightName.Length=wcslen(RightName.Buffer)*sizeof(wchar_t); RightName.MaximumLength=RightName.Length+sizeof(wchar_t); LsaRemoveAccountRights(PolicyHandle,GetSidFromUserData(sp[i].UserData.Data),FALSE,&RightName,1); } } LsaClose(PolicyHandle); } } } return res; }
bool DeleteACE(UserManager *panel,bool selection) { bool res=false,has_dir=false; CFarPanelSelection sp((HANDLE)panel,selection); if(sp.Number()) { for(int i=0;i<sp.Number();i++) if(sp[i].FileAttributes&FILE_ATTRIBUTE_DIRECTORY) { has_dir=true; break; } if(has_dir) ShowCustomError(mDelFolderWarning); else { TCHAR warning[TINY_BUFFER]; if(sp.Number()==1) { TCHAR Truncated[MAX_PATH]; _tcscpy(Truncated,sp[0].FileName); FSF.TruncPathStr(Truncated,50); FSF.sprintf(warning,GetMsg(mDelOne),Truncated); } else FSF.sprintf(warning,GetMsg(mDelACEN+NumberType(sp.Number())),sp.Number()); const TCHAR *MsgItems[]={GetMsg(mButtonDelete),warning,GetMsg(mButtonDelete),GetMsg(mButtonCancel)}; if(!Info.Message(&MainGuid,&DelACEMessageGuid,0,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),2)) for(int i=0;i<sp.Number();i++) { if(sp[i].UserData.FreeData) { if(UpdateAcl(panel,panel->level,GetSidFromUserData(sp[i].UserData.Data),GetItemTypeFromUserData(sp[i].UserData.Data),GetLevelFromUserData(sp[i].UserData.Data),actionDelete)) res=true; else break; } } } } return res; }
bool RemoveUser(UserManager *panel,bool selection) { bool res=false; CFarPanelSelection sp((HANDLE)panel,selection); if(sp.Number()) { TCHAR warning[TINY_BUFFER]; if(sp.Number()==1) { TCHAR Truncated[MAX_PATH]; _tcscpy(Truncated,sp[0].FileName); FSF.TruncPathStr(Truncated,50); FSF.sprintf(warning,GetMsg(mRemoveOne),Truncated); } else FSF.sprintf(warning,GetMsg(mRemoveUserN+NumberType(sp.Number())),sp.Number()); const TCHAR *MsgItems[]={GetMsg(mButtonRemove),warning,GetMsg(mButtonRemove),GetMsg(mButtonCancel)}; if(!Info.Message(&MainGuid,&RemoveUserMessageGuid,0,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),2)) { res=true; for(int i=0;i<sp.Number();i++) { if(sp[i].UserData.FreeData) { if(panel->global) { NetGroupDelUser(panel->domain,panel->nonfixed,GetWideNameFromUserData(sp[i].UserData.Data)); } else { LOCALGROUP_MEMBERS_INFO_0 new_member; new_member.lgrmi0_sid=GetSidFromUserData(sp[i].UserData.Data); NetLocalGroupDelMembers(panel->computer_ptr,panel->nonfixed,0,(LPBYTE)&new_member,1); } } } } } return res; }
AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words) { //Arguments from stack StringType property = eval(words); AnyType selector = eval(words); AnyType value = eval(words); Simulation * sim = m->GetSimulation(); unsigned char * partsBlock = (unsigned char*)&sim->parts[0]; int returnValue = 0; FormatType propertyFormat; int propertyOffset = GetPropertyOffset(property.Value(), propertyFormat); if(propertyOffset==-1) throw GeneralException("Invalid property"); //Selector int newValue; if(value.GetType() == TypeNumber) newValue = ((NumberType)value).Value(); else if(value.GetType() == TypeString) { newValue = GetParticleType(((StringType)value).Value()); if (newValue < 0 || newValue >= PT_NUM) throw GeneralException("Invalid element"); } else throw GeneralException("Invalid value for assignment"); if (property.Value() == "type" && (newValue < 0 || newValue >= PT_NUM)) throw GeneralException("Invalid element"); if(selector.GetType() == TypePoint || selector.GetType() == TypeNumber) { int partIndex = -1; if(selector.GetType() == TypePoint) { ui::Point tempPoint = ((PointType)selector).Value(); if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES) throw GeneralException("Invalid position"); } else partIndex = ((NumberType)selector).Value(); if(partIndex<0 || partIndex>NPART || sim->parts[partIndex].type==0) throw GeneralException("Invalid particle"); switch(propertyFormat) { case FormatInt: *((int*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue; break; case FormatFloat: *((float*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue; break; } returnValue = 1; } else if(selector.GetType() == TypeString && ((StringType)selector).Value() == "all") { switch(propertyFormat) { case FormatInt: { for(int j = 0; j < NPART; j++) if(sim->parts[j].type) { returnValue++; *((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue; } } break; case FormatFloat: { for(int j = 0; j < NPART; j++) if(sim->parts[j].type) { returnValue++; *((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue; } } break; } } else if(selector.GetType() == TypeString || selector.GetType() == TypeNumber) { int type; if(selector.GetType() == TypeNumber) type = ((NumberType)selector).Value(); else if(selector.GetType() == TypeString) type = GetParticleType(((StringType)selector).Value()); if(type<0 || type>=PT_NUM) throw GeneralException("Invalid particle type"); std::cout << propertyOffset << std::endl; switch(propertyFormat) { case FormatInt: { for(int j = 0; j < NPART; j++) if(sim->parts[j].type == type) { returnValue++; *((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue; } } break; case FormatFloat: { for(int j = 0; j < NPART; j++) if(sim->parts[j].type == type) { returnValue++; *((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue; } } break; } } else throw GeneralException("Invalid selector"); return NumberType(returnValue); }
AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words) { //Arguments from stack StringType property = eval(words); AnyType selector = eval(words); AnyType value = eval(words); Simulation * sim = m->GetSimulation(); unsigned char * partsBlock = (unsigned char*)&sim->parts[0]; int returnValue = 0; FormatType propertyFormat; int propertyOffset = GetPropertyOffset(property.Value(), propertyFormat); if(propertyOffset==-1) throw GeneralException("Invalid property"); //Selector int newValue; float newValuef; if (value.GetType() == TypeNumber) { newValue = newValuef = ((NumberType)value).Value(); } else if (value.GetType() == TypeFloat) { newValue = newValuef = ((FloatType)value).Value(); } else if(value.GetType() == TypeString) { if (property.Value() == "temp") { std::string newString = ((StringType)value).Value(); if (newString.at(newString.length()-1) == 'C') newValuef = atof(newString.substr(0, newString.length()-1).c_str())+273.15; else if (newString.at(newString.length()-1) == 'F') newValuef = (atof(newString.substr(0, newString.length()-1).c_str())-32.0f)*5/9+273.15f; else throw GeneralException("Invalid value for assignment"); } else { newValue = GetParticleType(((StringType)value).Value()); if (newValue < 0 || newValue >= PT_NUM) { // TODO: add element CAKE to invalidate this if (!strcasecmp(((StringType)value).Value().c_str(),"cake")) throw GeneralException("Cake is a lie, not an element"); throw GeneralException("Invalid element"); } } } else throw GeneralException("Invalid value for assignment"); if (property.Value() == "type" && (newValue < 0 || newValue >= PT_NUM || !sim->elements[newValue].Enabled)) throw GeneralException("Invalid element"); if(selector.GetType() == TypePoint || selector.GetType() == TypeNumber) { int partIndex = -1; if(selector.GetType() == TypePoint) { ui::Point tempPoint = ((PointType)selector).Value(); if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES) throw GeneralException("Invalid position"); } else partIndex = ((NumberType)selector).Value(); if(partIndex<0 || partIndex>NPART || sim->parts[partIndex].type==0) throw GeneralException("Invalid particle"); switch(propertyFormat) { case FormatInt: *((int*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue; break; case FormatFloat: *((float*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValuef; break; } returnValue = 1; } else if(selector.GetType() == TypeString && ((StringType)selector).Value() == "all") { switch(propertyFormat) { case FormatInt: { for(int j = 0; j < NPART; j++) if(sim->parts[j].type) { returnValue++; *((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue; } } break; case FormatFloat: { for(int j = 0; j < NPART; j++) if(sim->parts[j].type) { returnValue++; *((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValuef; } } break; } } else if(selector.GetType() == TypeString || selector.GetType() == TypeNumber) { int type; if(selector.GetType() == TypeNumber) type = ((NumberType)selector).Value(); else if(selector.GetType() == TypeString) type = GetParticleType(((StringType)selector).Value()); if(type<0 || type>=PT_NUM) throw GeneralException("Invalid particle type"); if(type==0) throw GeneralException("Cannot set properties of particles that do not exist"); std::cout << propertyOffset << std::endl; switch(propertyFormat) { case FormatInt: { for(int j = 0; j < NPART; j++) if(sim->parts[j].type == type) { returnValue++; *((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue; } } break; case FormatFloat: { for(int j = 0; j < NPART; j++) if(sim->parts[j].type == type) { returnValue++; *((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValuef; } } break; } } else throw GeneralException("Invalid selector"); return NumberType(returnValue); }
static void buildin_unpack(const vector<LuaValue>& args, vector<LuaValue>& rets) { auto table = args[0].getTable(); for (int i = 0; i < table->size(); ++i) { rets.push_back(table->get(LuaValue(NumberType(i + 1)))); } }
AnyType TPTScriptInterface::tptS_quit(std::deque<std::string> * words) { ui::Engine::Ref().Exit(); return NumberType(0); }