diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-06 17:57:25 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-06 19:54:37 (GMT) |
| commit | 622f2246ef31a05eb38e8f2ab3ac9c1bd9264920 (patch) | |
| tree | fb9009f6803f395c9da457039a823a0ffcdfc98a /src/cat | |
| parent | f75a3c264235d5edf162fd0f7bf6e04d629704f9 (diff) | |
| download | powder-622f2246ef31a05eb38e8f2ab3ac9c1bd9264920.zip powder-622f2246ef31a05eb38e8f2ab3ac9c1bd9264920.tar.gz | |
Fix TPTScript 'set' function
Diffstat (limited to 'src/cat')
| -rw-r--r-- | src/cat/LuaScriptInterface.cpp | 7 | ||||
| -rw-r--r-- | src/cat/TPTScriptInterface.cpp | 22 |
2 files changed, 18 insertions, 11 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 5aa6a73..40bcc08 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -310,7 +310,12 @@ int LuaScriptInterface::Command(std::string command) std::string LuaScriptInterface::FormatCommand(std::string command) { - return command; + if(command[0] == '!') + { + return "!"+legacy->FormatCommand(command.substr(1)); + } + else + return command; } LuaScriptInterface::~LuaScriptInterface() { diff --git a/src/cat/TPTScriptInterface.cpp b/src/cat/TPTScriptInterface.cpp index 3e4e5f1..d37bff3 100644 --- a/src/cat/TPTScriptInterface.cpp +++ b/src/cat/TPTScriptInterface.cpp @@ -194,6 +194,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words) AnyType value = eval(words); Simulation * sim = m->GetSimulation(); + unsigned char * partsBlock = (unsigned char*)&sim->parts[0]; int returnValue = 0; @@ -205,10 +206,10 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words) //Selector int newValue; - if(selector.GetType() == TypeNumber) - newValue = ((NumberType)selector).Value(); - else if(selector.GetType() == TypeString) - newValue = GetParticleType(((StringType)selector).Value()); + if(value.GetType() == TypeNumber) + newValue = ((NumberType)value).Value(); + else if(value.GetType() == TypeString) + newValue = GetParticleType(((StringType)value).Value()); else throw GeneralException("Invalid value for assignment"); @@ -230,10 +231,10 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words) switch(propertyFormat) { case FormatInt: - *((int*)(((unsigned char*)&sim->parts[partIndex])+propertyOffset)) = newValue; + *((int*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue; break; case FormatFloat: - *((float*)(((unsigned char*)&sim->parts[partIndex])+propertyOffset)) = newValue; + *((float*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue; break; } returnValue = 1; @@ -248,7 +249,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words) if(sim->parts[j].type) { returnValue++; - *((int*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = newValue; + *((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue; } } break; @@ -258,7 +259,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words) if(sim->parts[j].type) { returnValue++; - *((float*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = newValue; + *((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue; } } break; @@ -274,6 +275,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words) if(type<0 || type>=PT_NUM) throw GeneralException("Invalid particle type"); + std::cout << propertyOffset << std::endl; switch(propertyFormat) { case FormatInt: @@ -282,7 +284,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words) if(sim->parts[j].type == type) { returnValue++; - *((int*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = newValue; + *((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue; } } break; @@ -292,7 +294,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words) if(sim->parts[j].type == type) { returnValue++; - *((float*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = newValue; + *((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue; } } break; |
