compiledEval.cpp 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "console/console.h"
  24. #include "console/ast.h"
  25. #include "core/tAlgorithm.h"
  26. #include "core/strings/findMatch.h"
  27. #include "core/strings/stringUnit.h"
  28. #include "console/consoleInternal.h"
  29. #include "core/stream/fileStream.h"
  30. #include "console/compiler.h"
  31. #include "console/simBase.h"
  32. #include "console/telnetDebugger.h"
  33. #include "sim/netStringTable.h"
  34. #include "console/ICallMethod.h"
  35. #include "console/stringStack.h"
  36. #include "util/messaging/message.h"
  37. #include "core/frameAllocator.h"
  38. #ifndef TORQUE_TGB_ONLY
  39. #include "materials/materialDefinition.h"
  40. #include "materials/materialManager.h"
  41. #endif
  42. using namespace Compiler;
  43. enum EvalConstants {
  44. MaxStackSize = 1024,
  45. MethodOnComponent = -2
  46. };
  47. namespace Con
  48. {
  49. // Current script file name and root, these are registered as
  50. // console variables.
  51. extern StringTableEntry gCurrentFile;
  52. extern StringTableEntry gCurrentRoot;
  53. extern S32 gObjectCopyFailures;
  54. }
  55. /// Frame data for a foreach/foreach$ loop.
  56. struct IterStackRecord
  57. {
  58. /// If true, this is a foreach$ loop; if not, it's a foreach loop.
  59. bool mIsStringIter;
  60. /// The iterator variable.
  61. Dictionary::Entry* mVariable;
  62. /// Information for an object iterator loop.
  63. struct ObjectPos
  64. {
  65. /// The set being iterated over.
  66. SimSet* mSet;
  67. /// Current index in the set.
  68. U32 mIndex;
  69. };
  70. /// Information for a string iterator loop.
  71. struct StringPos
  72. {
  73. /// The raw string data on the string stack.
  74. const char* mString;
  75. /// Current parsing position.
  76. U32 mIndex;
  77. };
  78. union
  79. {
  80. ObjectPos mObj;
  81. StringPos mStr;
  82. } mData;
  83. };
  84. IterStackRecord iterStack[ MaxStackSize ];
  85. F64 floatStack[MaxStackSize];
  86. S64 intStack[MaxStackSize];
  87. StringStack STR;
  88. U32 _FLT = 0; ///< Stack pointer for floatStack.
  89. U32 _UINT = 0; ///< Stack pointer for intStack.
  90. U32 _ITER = 0; ///< Stack pointer for iterStack.
  91. namespace Con
  92. {
  93. const char *getNamespaceList(Namespace *ns)
  94. {
  95. U32 size = 1;
  96. Namespace * walk;
  97. for(walk = ns; walk; walk = walk->mParent)
  98. size += dStrlen(walk->mName) + 4;
  99. char *ret = Con::getReturnBuffer(size);
  100. ret[0] = 0;
  101. for(walk = ns; walk; walk = walk->mParent)
  102. {
  103. dStrcat(ret, walk->mName);
  104. if(walk->mParent)
  105. dStrcat(ret, " -> ");
  106. }
  107. return ret;
  108. }
  109. }
  110. //------------------------------------------------------------
  111. F64 consoleStringToNumber(const char *str, StringTableEntry file, U32 line)
  112. {
  113. F64 val = dAtof(str);
  114. if(val != 0)
  115. return val;
  116. else if(!dStricmp(str, "true"))
  117. return 1;
  118. else if(!dStricmp(str, "false"))
  119. return 0;
  120. else if(file)
  121. {
  122. Con::warnf(ConsoleLogEntry::General, "%s (%d): string always evaluates to 0.", file, line);
  123. return 0;
  124. }
  125. return 0;
  126. }
  127. //------------------------------------------------------------
  128. namespace Con
  129. {
  130. char *getReturnBuffer(U32 bufferSize)
  131. {
  132. return STR.getReturnBuffer(bufferSize);
  133. }
  134. char *getReturnBuffer( const char *stringToCopy )
  135. {
  136. U32 len = dStrlen( stringToCopy ) + 1;
  137. char *ret = STR.getReturnBuffer( len);
  138. dMemcpy( ret, stringToCopy, len );
  139. return ret;
  140. }
  141. char* getReturnBuffer( const String& str )
  142. {
  143. const U32 size = str.size();
  144. char* ret = STR.getReturnBuffer( size );
  145. dMemcpy( ret, str.c_str(), size );
  146. return ret;
  147. }
  148. char* getReturnBuffer( const StringBuilder& str )
  149. {
  150. char* buffer = Con::getReturnBuffer( str.length() + 1 );
  151. str.copy( buffer );
  152. buffer[ str.length() ] = '\0';
  153. return buffer;
  154. }
  155. char *getArgBuffer(U32 bufferSize)
  156. {
  157. return STR.getArgBuffer(bufferSize);
  158. }
  159. char *getFloatArg(F64 arg)
  160. {
  161. char *ret = STR.getArgBuffer(32);
  162. dSprintf(ret, 32, "%g", arg);
  163. return ret;
  164. }
  165. char *getIntArg(S32 arg)
  166. {
  167. char *ret = STR.getArgBuffer(32);
  168. dSprintf(ret, 32, "%d", arg);
  169. return ret;
  170. }
  171. char *getStringArg( const char *arg )
  172. {
  173. U32 len = dStrlen( arg ) + 1;
  174. char *ret = STR.getArgBuffer( len );
  175. dMemcpy( ret, arg, len );
  176. return ret;
  177. }
  178. char* getStringArg( const String& arg )
  179. {
  180. const U32 size = arg.size();
  181. char* ret = STR.getArgBuffer( size );
  182. dMemcpy( ret, arg.c_str(), size );
  183. return ret;
  184. }
  185. }
  186. //------------------------------------------------------------
  187. inline void ExprEvalState::setCurVarName(StringTableEntry name)
  188. {
  189. if(name[0] == '$')
  190. currentVariable = globalVars.lookup(name);
  191. else if( getStackDepth() > 0 )
  192. currentVariable = getCurrentFrame().lookup(name);
  193. if(!currentVariable && gWarnUndefinedScriptVariables)
  194. Con::warnf(ConsoleLogEntry::Script, "Variable referenced before assignment: %s", name);
  195. }
  196. inline void ExprEvalState::setCurVarNameCreate(StringTableEntry name)
  197. {
  198. if(name[0] == '$')
  199. currentVariable = globalVars.add(name);
  200. else if( getStackDepth() > 0 )
  201. currentVariable = getCurrentFrame().add(name);
  202. else
  203. {
  204. currentVariable = NULL;
  205. Con::warnf(ConsoleLogEntry::Script, "Accessing local variable in global scope... failed: %s", name);
  206. }
  207. }
  208. //------------------------------------------------------------
  209. inline S32 ExprEvalState::getIntVariable()
  210. {
  211. return currentVariable ? currentVariable->getIntValue() : 0;
  212. }
  213. inline F64 ExprEvalState::getFloatVariable()
  214. {
  215. return currentVariable ? currentVariable->getFloatValue() : 0;
  216. }
  217. inline const char *ExprEvalState::getStringVariable()
  218. {
  219. return currentVariable ? currentVariable->getStringValue() : "";
  220. }
  221. //------------------------------------------------------------
  222. inline void ExprEvalState::setIntVariable(S32 val)
  223. {
  224. AssertFatal(currentVariable != NULL, "Invalid evaluator state - trying to set null variable!");
  225. currentVariable->setIntValue(val);
  226. }
  227. inline void ExprEvalState::setFloatVariable(F64 val)
  228. {
  229. AssertFatal(currentVariable != NULL, "Invalid evaluator state - trying to set null variable!");
  230. currentVariable->setFloatValue(val);
  231. }
  232. inline void ExprEvalState::setStringVariable(const char *val)
  233. {
  234. AssertFatal(currentVariable != NULL, "Invalid evaluator state - trying to set null variable!");
  235. currentVariable->setStringValue(val);
  236. }
  237. //------------------------------------------------------------
  238. // Gets a component of an object's field value or a variable and returns it
  239. // in val.
  240. static void getFieldComponent( SimObject* object, StringTableEntry field, const char* array, StringTableEntry subField, char val[] )
  241. {
  242. const char* prevVal = NULL;
  243. // Grab value from object.
  244. if( object && field )
  245. prevVal = object->getDataField( field, array );
  246. // Otherwise, grab from the string stack. The value coming in will always
  247. // be a string because that is how multicomponent variables are handled.
  248. else
  249. prevVal = STR.getStringValue();
  250. // Make sure we got a value.
  251. if ( prevVal && *prevVal )
  252. {
  253. static const StringTableEntry xyzw[] =
  254. {
  255. StringTable->insert( "x" ),
  256. StringTable->insert( "y" ),
  257. StringTable->insert( "z" ),
  258. StringTable->insert( "w" )
  259. };
  260. static const StringTableEntry rgba[] =
  261. {
  262. StringTable->insert( "r" ),
  263. StringTable->insert( "g" ),
  264. StringTable->insert( "b" ),
  265. StringTable->insert( "a" )
  266. };
  267. // Translate xyzw and rgba into the indexed component
  268. // of the variable or field.
  269. if ( subField == xyzw[0] || subField == rgba[0] )
  270. dStrcpy( val, StringUnit::getUnit( prevVal, 0, " \t\n") );
  271. else if ( subField == xyzw[1] || subField == rgba[1] )
  272. dStrcpy( val, StringUnit::getUnit( prevVal, 1, " \t\n") );
  273. else if ( subField == xyzw[2] || subField == rgba[2] )
  274. dStrcpy( val, StringUnit::getUnit( prevVal, 2, " \t\n") );
  275. else if ( subField == xyzw[3] || subField == rgba[3] )
  276. dStrcpy( val, StringUnit::getUnit( prevVal, 3, " \t\n") );
  277. else
  278. val[0] = 0;
  279. }
  280. else
  281. val[0] = 0;
  282. }
  283. // Sets a component of an object's field value based on the sub field. 'x' will
  284. // set the first field, 'y' the second, and 'z' the third.
  285. static void setFieldComponent( SimObject* object, StringTableEntry field, const char* array, StringTableEntry subField )
  286. {
  287. // Copy the current string value
  288. char strValue[1024];
  289. dStrncpy( strValue, STR.getStringValue(), 1024 );
  290. char val[1024] = "";
  291. const char* prevVal = NULL;
  292. // Set the value on an object field.
  293. if( object && field )
  294. prevVal = object->getDataField( field, array );
  295. // Set the value on a variable.
  296. else if( gEvalState.currentVariable )
  297. prevVal = gEvalState.getStringVariable();
  298. // Ensure that the variable has a value
  299. if (!prevVal)
  300. return;
  301. static const StringTableEntry xyzw[] =
  302. {
  303. StringTable->insert( "x" ),
  304. StringTable->insert( "y" ),
  305. StringTable->insert( "z" ),
  306. StringTable->insert( "w" )
  307. };
  308. static const StringTableEntry rgba[] =
  309. {
  310. StringTable->insert( "r" ),
  311. StringTable->insert( "g" ),
  312. StringTable->insert( "b" ),
  313. StringTable->insert( "a" )
  314. };
  315. // Insert the value into the specified
  316. // component of the string.
  317. if ( subField == xyzw[0] || subField == rgba[0] )
  318. dStrcpy( val, StringUnit::setUnit( prevVal, 0, strValue, " \t\n") );
  319. else if ( subField == xyzw[1] || subField == rgba[1] )
  320. dStrcpy( val, StringUnit::setUnit( prevVal, 1, strValue, " \t\n") );
  321. else if ( subField == xyzw[2] || subField == rgba[2] )
  322. dStrcpy( val, StringUnit::setUnit( prevVal, 2, strValue, " \t\n") );
  323. else if ( subField == xyzw[3] || subField == rgba[3] )
  324. dStrcpy( val, StringUnit::setUnit( prevVal, 3, strValue, " \t\n") );
  325. if ( val[0] != 0 )
  326. {
  327. // Update the field or variable.
  328. if( object && field )
  329. object->setDataField( field, 0, val );
  330. else if( gEvalState.currentVariable )
  331. gEvalState.setStringVariable( val );
  332. }
  333. }
  334. const char *CodeBlock::exec(U32 ip, const char *functionName, Namespace *thisNamespace, U32 argc, const char **argv, bool noCalls, StringTableEntry packageName, S32 setFrame)
  335. {
  336. #ifdef TORQUE_DEBUG
  337. U32 stackStart = STR.mStartStackSize;
  338. #endif
  339. static char traceBuffer[1024];
  340. U32 i;
  341. U32 iterDepth = 0;
  342. incRefCount();
  343. F64 *curFloatTable;
  344. char *curStringTable;
  345. S32 curStringTableLen = 0; //clint to ensure we dont overwrite it
  346. STR.clearFunctionOffset();
  347. StringTableEntry thisFunctionName = NULL;
  348. bool popFrame = false;
  349. if(argv)
  350. {
  351. // assume this points into a function decl:
  352. U32 fnArgc = code[ip + 5];
  353. thisFunctionName = U32toSTE(code[ip]);
  354. argc = getMin(argc-1, fnArgc); // argv[0] is func name
  355. if(gEvalState.traceOn)
  356. {
  357. traceBuffer[0] = 0;
  358. dStrcat(traceBuffer, "Entering ");
  359. if(packageName)
  360. {
  361. dStrcat(traceBuffer, "[");
  362. dStrcat(traceBuffer, packageName);
  363. dStrcat(traceBuffer, "]");
  364. }
  365. if(thisNamespace && thisNamespace->mName)
  366. {
  367. dSprintf(traceBuffer + dStrlen(traceBuffer), sizeof(traceBuffer) - dStrlen(traceBuffer),
  368. "%s::%s(", thisNamespace->mName, thisFunctionName);
  369. }
  370. else
  371. {
  372. dSprintf(traceBuffer + dStrlen(traceBuffer), sizeof(traceBuffer) - dStrlen(traceBuffer),
  373. "%s(", thisFunctionName);
  374. }
  375. for(i = 0; i < argc; i++)
  376. {
  377. dStrcat(traceBuffer, argv[i+1]);
  378. if(i != argc - 1)
  379. dStrcat(traceBuffer, ", ");
  380. }
  381. dStrcat(traceBuffer, ")");
  382. Con::printf("%s", traceBuffer);
  383. }
  384. gEvalState.pushFrame(thisFunctionName, thisNamespace);
  385. popFrame = true;
  386. for(i = 0; i < argc; i++)
  387. {
  388. StringTableEntry var = U32toSTE(code[ip + i + 6]);
  389. gEvalState.setCurVarNameCreate(var);
  390. gEvalState.setStringVariable(argv[i+1]);
  391. }
  392. ip = ip + fnArgc + 6;
  393. curFloatTable = functionFloats;
  394. curStringTable = functionStrings;
  395. curStringTableLen = functionStringsMaxLen;
  396. }
  397. else
  398. {
  399. curFloatTable = globalFloats;
  400. curStringTable = globalStrings;
  401. curStringTableLen = globalStringsMaxLen;
  402. // If requested stack frame isn't available, request a new one
  403. // (this prevents assert failures when creating local
  404. // variables without a stack frame)
  405. if (gEvalState.getStackDepth() <= setFrame)
  406. setFrame = -1;
  407. // Do we want this code to execute using a new stack frame?
  408. if (setFrame < 0)
  409. {
  410. gEvalState.pushFrame(NULL, NULL);
  411. popFrame = true;
  412. }
  413. else
  414. {
  415. // We want to copy a reference to an existing stack frame
  416. // on to the top of the stack. Any change that occurs to
  417. // the locals during this new frame will also occur in the
  418. // original frame.
  419. S32 stackIndex = gEvalState.getStackDepth() - setFrame - 1;
  420. gEvalState.pushFrameRef( stackIndex );
  421. popFrame = true;
  422. }
  423. }
  424. // Grab the state of the telenet debugger here once
  425. // so that the push and pop frames are always balanced.
  426. const bool telDebuggerOn = TelDebugger && TelDebugger->isConnected();
  427. if ( telDebuggerOn && setFrame < 0 )
  428. TelDebugger->pushStackFrame();
  429. StringTableEntry var, objParent;
  430. StringTableEntry fnName;
  431. StringTableEntry fnNamespace, fnPackage;
  432. // Add local object creation stack [7/9/2007 Black]
  433. static const U32 objectCreationStackSize = 32;
  434. U32 objectCreationStackIndex = 0;
  435. struct {
  436. SimObject *newObject;
  437. U32 failJump;
  438. } objectCreationStack[ objectCreationStackSize ];
  439. SimObject *currentNewObject = 0;
  440. U32 failJump = 0;
  441. StringTableEntry prevField = NULL;
  442. StringTableEntry curField = NULL;
  443. SimObject *prevObject = NULL;
  444. SimObject *curObject = NULL;
  445. SimObject *saveObject=NULL;
  446. Namespace::Entry *nsEntry;
  447. Namespace *ns;
  448. const char* curFNDocBlock = NULL;
  449. const char* curNSDocBlock = NULL;
  450. const S32 nsDocLength = 128;
  451. char nsDocBlockClass[nsDocLength];
  452. U32 callArgc;
  453. const char **callArgv;
  454. static char curFieldArray[256];
  455. static char prevFieldArray[256];
  456. CodeBlock *saveCodeBlock = smCurrentCodeBlock;
  457. smCurrentCodeBlock = this;
  458. if(this->name)
  459. {
  460. Con::gCurrentFile = this->name;
  461. Con::gCurrentRoot = this->modPath;
  462. }
  463. const char * val;
  464. // The frame temp is used by the variable accessor ops (OP_SAVEFIELD_* and
  465. // OP_LOADFIELD_*) to store temporary values for the fields.
  466. static S32 VAL_BUFFER_SIZE = 1024;
  467. FrameTemp<char> valBuffer( VAL_BUFFER_SIZE );
  468. for(;;)
  469. {
  470. U32 instruction = code[ip++];
  471. nsEntry = NULL;
  472. breakContinue:
  473. switch(instruction)
  474. {
  475. case OP_FUNC_DECL:
  476. if(!noCalls)
  477. {
  478. fnName = U32toSTE(code[ip]);
  479. fnNamespace = U32toSTE(code[ip+1]);
  480. fnPackage = U32toSTE(code[ip+2]);
  481. bool hasBody = ( code[ ip + 3 ] & 0x01 ) != 0;
  482. U32 lineNumber = code[ ip + 3 ] >> 1;
  483. Namespace::unlinkPackages();
  484. ns = Namespace::find(fnNamespace, fnPackage);
  485. ns->addFunction(fnName, this, hasBody ? ip : 0, curFNDocBlock ? dStrdup( curFNDocBlock ) : NULL, lineNumber );// if no body, set the IP to 0
  486. if( curNSDocBlock )
  487. {
  488. if( fnNamespace == StringTable->lookup( nsDocBlockClass ) )
  489. {
  490. char *usageStr = dStrdup( curNSDocBlock );
  491. usageStr[dStrlen(usageStr)] = '\0';
  492. ns->mUsage = usageStr;
  493. ns->mCleanUpUsage = true;
  494. curNSDocBlock = NULL;
  495. }
  496. }
  497. Namespace::relinkPackages();
  498. // If we had a docblock, it's definitely not valid anymore, so clear it out.
  499. curFNDocBlock = NULL;
  500. //Con::printf("Adding function %s::%s (%d)", fnNamespace, fnName, ip);
  501. }
  502. ip = code[ip + 4];
  503. break;
  504. case OP_CREATE_OBJECT:
  505. {
  506. // Read some useful info.
  507. objParent = U32toSTE(code[ip ]);
  508. bool isDataBlock = code[ip + 1];
  509. bool isInternal = code[ip + 2];
  510. bool isSingleton = code[ip + 3];
  511. U32 lineNumber = code[ip + 4];
  512. failJump = code[ip + 5];
  513. // If we don't allow calls, we certainly don't allow creating objects!
  514. // Moved this to after failJump is set. Engine was crashing when
  515. // noCalls = true and an object was being created at the beginning of
  516. // a file. ADL.
  517. if(noCalls)
  518. {
  519. ip = failJump;
  520. break;
  521. }
  522. // Push the old info to the stack
  523. //Assert( objectCreationStackIndex < objectCreationStackSize );
  524. objectCreationStack[ objectCreationStackIndex ].newObject = currentNewObject;
  525. objectCreationStack[ objectCreationStackIndex++ ].failJump = failJump;
  526. // Get the constructor information off the stack.
  527. STR.getArgcArgv(NULL, &callArgc, &callArgv);
  528. const char* objectName = callArgv[ 2 ];
  529. // Con::printf("Creating object...");
  530. // objectName = argv[1]...
  531. currentNewObject = NULL;
  532. // Are we creating a datablock? If so, deal with case where we override
  533. // an old one.
  534. if(isDataBlock)
  535. {
  536. // Con::printf(" - is a datablock");
  537. // Find the old one if any.
  538. SimObject *db = Sim::getDataBlockGroup()->findObject( objectName );
  539. // Make sure we're not changing types on ourselves...
  540. if(db && dStricmp(db->getClassName(), callArgv[1]))
  541. {
  542. Con::errorf(ConsoleLogEntry::General, "%s: Cannot re-declare data block %s with a different class.", getFileLine(ip), objectName);
  543. ip = failJump;
  544. STR.popFrame();
  545. break;
  546. }
  547. // If there was one, set the currentNewObject and move on.
  548. if(db)
  549. currentNewObject = db;
  550. }
  551. else if (!isInternal)
  552. {
  553. // IF we aren't looking at a local/internal object, then check if
  554. // this object already exists in the global space
  555. AbstractClassRep* rep = AbstractClassRep::findClassRep( objectName );
  556. if (rep != NULL) {
  557. Con::errorf(ConsoleLogEntry::General, "%s: Cannot name object [%s] the same name as a script class.",
  558. getFileLine(ip), objectName);
  559. ip = failJump;
  560. STR.popFrame();
  561. break;
  562. }
  563. SimObject *obj = Sim::findObject( objectName );
  564. if (obj /*&& !obj->isLocalName()*/)
  565. {
  566. if ( isSingleton )
  567. {
  568. // Make sure we're not trying to change types
  569. if ( dStricmp( obj->getClassName(), callArgv[1] ) != 0 )
  570. {
  571. Con::errorf(ConsoleLogEntry::General, "%s: Cannot re-declare object [%s] with a different class [%s] - was [%s].",
  572. getFileLine(ip), objectName, callArgv[1], obj->getClassName());
  573. ip = failJump;
  574. STR.popFrame();
  575. break;
  576. }
  577. // We're creating a singleton, so use the found object
  578. // instead of creating a new object.
  579. currentNewObject = obj;
  580. }
  581. else
  582. {
  583. const char* redefineBehavior = Con::getVariable( "$Con::redefineBehavior" );
  584. if( dStricmp( redefineBehavior, "replaceExisting" ) == 0 )
  585. {
  586. // Save our constructor args as the argv vector is stored on the
  587. // string stack and may get stomped if deleteObject triggers
  588. // script execution.
  589. const char* savedArgv[ StringStack::MaxArgs ];
  590. dMemcpy( savedArgv, callArgv, sizeof( savedArgv[ 0 ] ) * callArgc );
  591. obj->deleteObject();
  592. obj = NULL;
  593. dMemcpy( callArgv, savedArgv, sizeof( callArgv[ 0 ] ) * callArgc );
  594. }
  595. else if( dStricmp( redefineBehavior, "renameNew" ) == 0 )
  596. {
  597. for( U32 i = 1;; ++ i )
  598. {
  599. String newName = String::ToString( "%s%i", objectName, i );
  600. if( !Sim::findObject( newName ) )
  601. {
  602. objectName = StringTable->insert( newName );
  603. break;
  604. }
  605. }
  606. }
  607. else if( dStricmp( redefineBehavior, "unnameNew" ) == 0 )
  608. {
  609. objectName = StringTable->insert( "" );
  610. }
  611. else if( dStricmp( redefineBehavior, "postfixNew" ) == 0 )
  612. {
  613. const char* postfix = Con::getVariable( "$Con::redefineBehaviorPostfix" );
  614. String newName = String::ToString( "%s%s", objectName, postfix );
  615. if( Sim::findObject( newName ) )
  616. {
  617. Con::errorf( ConsoleLogEntry::General, "%s: Cannot re-declare object with postfix [%s].",
  618. getFileLine(ip), newName.c_str() );
  619. ip = failJump;
  620. STR.popFrame();
  621. break;
  622. }
  623. else
  624. objectName = StringTable->insert( newName );
  625. }
  626. else
  627. {
  628. Con::errorf(ConsoleLogEntry::General, "%s: Cannot re-declare object [%s].",
  629. getFileLine(ip), objectName);
  630. ip = failJump;
  631. STR.popFrame();
  632. break;
  633. }
  634. }
  635. }
  636. }
  637. STR.popFrame();
  638. if(!currentNewObject)
  639. {
  640. // Well, looks like we have to create a new object.
  641. ConsoleObject *object = ConsoleObject::create(callArgv[1]);
  642. // Deal with failure!
  643. if(!object)
  644. {
  645. Con::errorf(ConsoleLogEntry::General, "%s: Unable to instantiate non-conobject class %s.", getFileLine(ip), callArgv[1]);
  646. ip = failJump;
  647. break;
  648. }
  649. // Do special datablock init if appropros
  650. if(isDataBlock)
  651. {
  652. SimDataBlock *dataBlock = dynamic_cast<SimDataBlock *>(object);
  653. if(dataBlock)
  654. {
  655. dataBlock->assignId();
  656. }
  657. else
  658. {
  659. // They tried to make a non-datablock with a datablock keyword!
  660. Con::errorf(ConsoleLogEntry::General, "%s: Unable to instantiate non-datablock class %s.", getFileLine(ip), callArgv[1]);
  661. // Clean up...
  662. delete object;
  663. ip = failJump;
  664. break;
  665. }
  666. }
  667. // Finally, set currentNewObject to point to the new one.
  668. currentNewObject = dynamic_cast<SimObject *>(object);
  669. // Deal with the case of a non-SimObject.
  670. if(!currentNewObject)
  671. {
  672. Con::errorf(ConsoleLogEntry::General, "%s: Unable to instantiate non-SimObject class %s.", getFileLine(ip), callArgv[1]);
  673. delete object;
  674. ip = failJump;
  675. break;
  676. }
  677. // Set the declaration line
  678. currentNewObject->setDeclarationLine(lineNumber);
  679. // Set the file that this object was created in
  680. currentNewObject->setFilename(name);
  681. // Does it have a parent object? (ie, the copy constructor : syntax, not inheriance)
  682. if(*objParent)
  683. {
  684. // Find it!
  685. SimObject *parent;
  686. if(Sim::findObject(objParent, parent))
  687. {
  688. // Con::printf(" - Parent object found: %s", parent->getClassName());
  689. currentNewObject->setCopySource( parent );
  690. currentNewObject->assignFieldsFrom( parent );
  691. }
  692. else
  693. {
  694. if ( Con::gObjectCopyFailures == -1 )
  695. Con::errorf(ConsoleLogEntry::General, "%s: Unable to find parent object %s for %s.", getFileLine(ip), objParent, callArgv[1]);
  696. else
  697. ++Con::gObjectCopyFailures;
  698. // Fail to create the object.
  699. delete object;
  700. ip = failJump;
  701. break;
  702. }
  703. }
  704. // If a name was passed, assign it.
  705. if( objectName[ 0 ] )
  706. {
  707. if( !isInternal )
  708. currentNewObject->assignName( objectName );
  709. else
  710. currentNewObject->setInternalName( objectName );
  711. // Set the original name
  712. currentNewObject->setOriginalName( objectName );
  713. }
  714. // Do the constructor parameters.
  715. if(!currentNewObject->processArguments(callArgc-3, callArgv+3))
  716. {
  717. delete currentNewObject;
  718. currentNewObject = NULL;
  719. ip = failJump;
  720. break;
  721. }
  722. // If it's not a datablock, allow people to modify bits of it.
  723. if(!isDataBlock)
  724. {
  725. currentNewObject->setModStaticFields(true);
  726. currentNewObject->setModDynamicFields(true);
  727. }
  728. }
  729. // Advance the IP past the create info...
  730. ip += 6;
  731. break;
  732. }
  733. case OP_ADD_OBJECT:
  734. {
  735. // See OP_SETCURVAR for why we do this.
  736. curFNDocBlock = NULL;
  737. curNSDocBlock = NULL;
  738. // Do we place this object at the root?
  739. bool placeAtRoot = code[ip++];
  740. // Con::printf("Adding object %s", currentNewObject->getName());
  741. // Make sure it wasn't already added, then add it.
  742. if(currentNewObject->isProperlyAdded() == false)
  743. {
  744. bool ret = false;
  745. Message *msg = dynamic_cast<Message *>(currentNewObject);
  746. if(msg)
  747. {
  748. SimObjectId id = Message::getNextMessageID();
  749. if(id != 0xffffffff)
  750. ret = currentNewObject->registerObject(id);
  751. else
  752. Con::errorf("%s: No more object IDs available for messages", getFileLine(ip));
  753. }
  754. else
  755. ret = currentNewObject->registerObject();
  756. if(! ret)
  757. {
  758. // This error is usually caused by failing to call Parent::initPersistFields in the class' initPersistFields().
  759. Con::warnf(ConsoleLogEntry::General, "%s: Register object failed for object %s of class %s.", getFileLine(ip), currentNewObject->getName(), currentNewObject->getClassName());
  760. delete currentNewObject;
  761. ip = failJump;
  762. break;
  763. }
  764. }
  765. // Are we dealing with a datablock?
  766. SimDataBlock *dataBlock = dynamic_cast<SimDataBlock *>(currentNewObject);
  767. static String errorStr;
  768. // If so, preload it.
  769. if(dataBlock && !dataBlock->preload(true, errorStr))
  770. {
  771. Con::errorf(ConsoleLogEntry::General, "%s: preload failed for %s: %s.", getFileLine(ip),
  772. currentNewObject->getName(), errorStr.c_str());
  773. dataBlock->deleteObject();
  774. ip = failJump;
  775. break;
  776. }
  777. // What group will we be added to, if any?
  778. U32 groupAddId = intStack[_UINT];
  779. SimGroup *grp = NULL;
  780. SimSet *set = NULL;
  781. bool isMessage = dynamic_cast<Message *>(currentNewObject) != NULL;
  782. if(!placeAtRoot || !currentNewObject->getGroup())
  783. {
  784. if(! isMessage)
  785. {
  786. if(! placeAtRoot)
  787. {
  788. // Otherwise just add to the requested group or set.
  789. if(!Sim::findObject(groupAddId, grp))
  790. Sim::findObject(groupAddId, set);
  791. }
  792. if(placeAtRoot)
  793. {
  794. // Deal with the instantGroup if we're being put at the root or we're adding to a component.
  795. if( Con::gInstantGroup.isEmpty()
  796. || !Sim::findObject( Con::gInstantGroup, grp ) )
  797. grp = Sim::getRootGroup();
  798. }
  799. }
  800. // If we didn't get a group, then make sure we have a pointer to
  801. // the rootgroup.
  802. if(!grp)
  803. grp = Sim::getRootGroup();
  804. // add to the parent group
  805. grp->addObject(currentNewObject);
  806. // If for some reason the add failed, add the object to the
  807. // root group so it won't leak.
  808. if( !currentNewObject->getGroup() )
  809. Sim::getRootGroup()->addObject( currentNewObject );
  810. // add to any set we might be in
  811. if(set)
  812. set->addObject(currentNewObject);
  813. }
  814. // store the new object's ID on the stack (overwriting the group/set
  815. // id, if one was given, otherwise getting pushed)
  816. if(placeAtRoot)
  817. intStack[_UINT] = currentNewObject->getId();
  818. else
  819. intStack[++_UINT] = currentNewObject->getId();
  820. break;
  821. }
  822. case OP_END_OBJECT:
  823. {
  824. // If we're not to be placed at the root, make sure we clean up
  825. // our group reference.
  826. bool placeAtRoot = code[ip++];
  827. if(!placeAtRoot)
  828. _UINT--;
  829. break;
  830. }
  831. case OP_FINISH_OBJECT:
  832. {
  833. //Assert( objectCreationStackIndex >= 0 );
  834. // Restore the object info from the stack [7/9/2007 Black]
  835. currentNewObject = objectCreationStack[ --objectCreationStackIndex ].newObject;
  836. failJump = objectCreationStack[ objectCreationStackIndex ].failJump;
  837. break;
  838. }
  839. case OP_JMPIFFNOT:
  840. if(floatStack[_FLT--])
  841. {
  842. ip++;
  843. break;
  844. }
  845. ip = code[ip];
  846. break;
  847. case OP_JMPIFNOT:
  848. if(intStack[_UINT--])
  849. {
  850. ip++;
  851. break;
  852. }
  853. ip = code[ip];
  854. break;
  855. case OP_JMPIFF:
  856. if(!floatStack[_FLT--])
  857. {
  858. ip++;
  859. break;
  860. }
  861. ip = code[ip];
  862. break;
  863. case OP_JMPIF:
  864. if(!intStack[_UINT--])
  865. {
  866. ip ++;
  867. break;
  868. }
  869. ip = code[ip];
  870. break;
  871. case OP_JMPIFNOT_NP:
  872. if(intStack[_UINT])
  873. {
  874. _UINT--;
  875. ip++;
  876. break;
  877. }
  878. ip = code[ip];
  879. break;
  880. case OP_JMPIF_NP:
  881. if(!intStack[_UINT])
  882. {
  883. _UINT--;
  884. ip++;
  885. break;
  886. }
  887. ip = code[ip];
  888. break;
  889. case OP_JMP:
  890. ip = code[ip];
  891. break;
  892. // This fixes a bug when not explicitly returning a value.
  893. case OP_RETURN_VOID:
  894. STR.setStringValue("");
  895. // We're falling thru here on purpose.
  896. case OP_RETURN:
  897. if( iterDepth > 0 )
  898. {
  899. // Clear iterator state.
  900. while( iterDepth > 0 )
  901. {
  902. iterStack[ -- _ITER ].mIsStringIter = false;
  903. -- iterDepth;
  904. }
  905. const char* returnValue = STR.getStringValue();
  906. STR.rewind();
  907. STR.setStringValue( returnValue ); // Not nice but works.
  908. }
  909. goto execFinished;
  910. case OP_CMPEQ:
  911. intStack[_UINT+1] = bool(floatStack[_FLT] == floatStack[_FLT-1]);
  912. _UINT++;
  913. _FLT -= 2;
  914. break;
  915. case OP_CMPGR:
  916. intStack[_UINT+1] = bool(floatStack[_FLT] > floatStack[_FLT-1]);
  917. _UINT++;
  918. _FLT -= 2;
  919. break;
  920. case OP_CMPGE:
  921. intStack[_UINT+1] = bool(floatStack[_FLT] >= floatStack[_FLT-1]);
  922. _UINT++;
  923. _FLT -= 2;
  924. break;
  925. case OP_CMPLT:
  926. intStack[_UINT+1] = bool(floatStack[_FLT] < floatStack[_FLT-1]);
  927. _UINT++;
  928. _FLT -= 2;
  929. break;
  930. case OP_CMPLE:
  931. intStack[_UINT+1] = bool(floatStack[_FLT] <= floatStack[_FLT-1]);
  932. _UINT++;
  933. _FLT -= 2;
  934. break;
  935. case OP_CMPNE:
  936. intStack[_UINT+1] = bool(floatStack[_FLT] != floatStack[_FLT-1]);
  937. _UINT++;
  938. _FLT -= 2;
  939. break;
  940. case OP_XOR:
  941. intStack[_UINT-1] = intStack[_UINT] ^ intStack[_UINT-1];
  942. _UINT--;
  943. break;
  944. case OP_MOD:
  945. if( intStack[_UINT-1] != 0 )
  946. intStack[_UINT-1] = intStack[_UINT] % intStack[_UINT-1];
  947. else
  948. intStack[_UINT-1] = 0;
  949. _UINT--;
  950. break;
  951. case OP_BITAND:
  952. intStack[_UINT-1] = intStack[_UINT] & intStack[_UINT-1];
  953. _UINT--;
  954. break;
  955. case OP_BITOR:
  956. intStack[_UINT-1] = intStack[_UINT] | intStack[_UINT-1];
  957. _UINT--;
  958. break;
  959. case OP_NOT:
  960. intStack[_UINT] = !intStack[_UINT];
  961. break;
  962. case OP_NOTF:
  963. intStack[_UINT+1] = !floatStack[_FLT];
  964. _FLT--;
  965. _UINT++;
  966. break;
  967. case OP_ONESCOMPLEMENT:
  968. intStack[_UINT] = ~intStack[_UINT];
  969. break;
  970. case OP_SHR:
  971. intStack[_UINT-1] = intStack[_UINT] >> intStack[_UINT-1];
  972. _UINT--;
  973. break;
  974. case OP_SHL:
  975. intStack[_UINT-1] = intStack[_UINT] << intStack[_UINT-1];
  976. _UINT--;
  977. break;
  978. case OP_AND:
  979. intStack[_UINT-1] = intStack[_UINT] && intStack[_UINT-1];
  980. _UINT--;
  981. break;
  982. case OP_OR:
  983. intStack[_UINT-1] = intStack[_UINT] || intStack[_UINT-1];
  984. _UINT--;
  985. break;
  986. case OP_ADD:
  987. floatStack[_FLT-1] = floatStack[_FLT] + floatStack[_FLT-1];
  988. _FLT--;
  989. break;
  990. case OP_SUB:
  991. floatStack[_FLT-1] = floatStack[_FLT] - floatStack[_FLT-1];
  992. _FLT--;
  993. break;
  994. case OP_MUL:
  995. floatStack[_FLT-1] = floatStack[_FLT] * floatStack[_FLT-1];
  996. _FLT--;
  997. break;
  998. case OP_DIV:
  999. floatStack[_FLT-1] = floatStack[_FLT] / floatStack[_FLT-1];
  1000. _FLT--;
  1001. break;
  1002. case OP_NEG:
  1003. floatStack[_FLT] = -floatStack[_FLT];
  1004. break;
  1005. case OP_SETCURVAR:
  1006. var = U32toSTE(code[ip]);
  1007. ip++;
  1008. // If a variable is set, then these must be NULL. It is necessary
  1009. // to set this here so that the vector parser can appropriately
  1010. // identify whether it's dealing with a vector.
  1011. prevField = NULL;
  1012. prevObject = NULL;
  1013. curObject = NULL;
  1014. gEvalState.setCurVarName(var);
  1015. // In order to let docblocks work properly with variables, we have
  1016. // clear the current docblock when we do an assign. This way it
  1017. // won't inappropriately carry forward to following function decls.
  1018. curFNDocBlock = NULL;
  1019. curNSDocBlock = NULL;
  1020. break;
  1021. case OP_SETCURVAR_CREATE:
  1022. var = U32toSTE(code[ip]);
  1023. ip++;
  1024. // See OP_SETCURVAR
  1025. prevField = NULL;
  1026. prevObject = NULL;
  1027. curObject = NULL;
  1028. gEvalState.setCurVarNameCreate(var);
  1029. // See OP_SETCURVAR for why we do this.
  1030. curFNDocBlock = NULL;
  1031. curNSDocBlock = NULL;
  1032. break;
  1033. case OP_SETCURVAR_ARRAY:
  1034. var = STR.getSTValue();
  1035. // See OP_SETCURVAR
  1036. prevField = NULL;
  1037. prevObject = NULL;
  1038. curObject = NULL;
  1039. gEvalState.setCurVarName(var);
  1040. // See OP_SETCURVAR for why we do this.
  1041. curFNDocBlock = NULL;
  1042. curNSDocBlock = NULL;
  1043. break;
  1044. case OP_SETCURVAR_ARRAY_CREATE:
  1045. var = STR.getSTValue();
  1046. // See OP_SETCURVAR
  1047. prevField = NULL;
  1048. prevObject = NULL;
  1049. curObject = NULL;
  1050. gEvalState.setCurVarNameCreate(var);
  1051. // See OP_SETCURVAR for why we do this.
  1052. curFNDocBlock = NULL;
  1053. curNSDocBlock = NULL;
  1054. break;
  1055. case OP_LOADVAR_UINT:
  1056. intStack[_UINT+1] = gEvalState.getIntVariable();
  1057. _UINT++;
  1058. break;
  1059. case OP_LOADVAR_FLT:
  1060. floatStack[_FLT+1] = gEvalState.getFloatVariable();
  1061. _FLT++;
  1062. break;
  1063. case OP_LOADVAR_STR:
  1064. val = gEvalState.getStringVariable();
  1065. STR.setStringValue(val);
  1066. break;
  1067. case OP_SAVEVAR_UINT:
  1068. gEvalState.setIntVariable(intStack[_UINT]);
  1069. break;
  1070. case OP_SAVEVAR_FLT:
  1071. gEvalState.setFloatVariable(floatStack[_FLT]);
  1072. break;
  1073. case OP_SAVEVAR_STR:
  1074. gEvalState.setStringVariable(STR.getStringValue());
  1075. break;
  1076. case OP_SETCUROBJECT:
  1077. // Save the previous object for parsing vector fields.
  1078. prevObject = curObject;
  1079. val = STR.getStringValue();
  1080. // Sim::findObject will sometimes find valid objects from
  1081. // multi-component strings. This makes sure that doesn't
  1082. // happen.
  1083. for( const char* check = val; *check; check++ )
  1084. {
  1085. if( *check == ' ' )
  1086. {
  1087. val = "";
  1088. break;
  1089. }
  1090. }
  1091. curObject = Sim::findObject(val);
  1092. break;
  1093. case OP_SETCUROBJECT_INTERNAL:
  1094. ++ip; // To skip the recurse flag if the object wasn't found
  1095. if(curObject)
  1096. {
  1097. SimSet *set = dynamic_cast<SimSet *>(curObject);
  1098. if(set)
  1099. {
  1100. StringTableEntry intName = StringTable->insert(STR.getStringValue());
  1101. bool recurse = code[ip-1];
  1102. SimObject *obj = set->findObjectByInternalName(intName, recurse);
  1103. intStack[_UINT+1] = obj ? obj->getId() : 0;
  1104. _UINT++;
  1105. }
  1106. else
  1107. {
  1108. Con::errorf(ConsoleLogEntry::Script, "%s: Attempt to use -> on non-set %s of class %s.", getFileLine(ip-2), curObject->getName(), curObject->getClassName());
  1109. intStack[_UINT] = 0;
  1110. }
  1111. }
  1112. break;
  1113. case OP_SETCUROBJECT_NEW:
  1114. curObject = currentNewObject;
  1115. break;
  1116. case OP_SETCURFIELD:
  1117. // Save the previous field for parsing vector fields.
  1118. prevField = curField;
  1119. dStrcpy( prevFieldArray, curFieldArray );
  1120. curField = U32toSTE(code[ip]);
  1121. curFieldArray[0] = 0;
  1122. ip++;
  1123. break;
  1124. case OP_SETCURFIELD_ARRAY:
  1125. dStrcpy(curFieldArray, STR.getStringValue());
  1126. break;
  1127. case OP_SETCURFIELD_TYPE:
  1128. if(curObject)
  1129. curObject->setDataFieldType(code[ip], curField, curFieldArray);
  1130. ip++;
  1131. break;
  1132. case OP_LOADFIELD_UINT:
  1133. if(curObject)
  1134. intStack[_UINT+1] = U32(dAtoi(curObject->getDataField(curField, curFieldArray)));
  1135. else
  1136. {
  1137. // The field is not being retrieved from an object. Maybe it's
  1138. // a special accessor?
  1139. getFieldComponent( prevObject, prevField, prevFieldArray, curField, valBuffer );
  1140. intStack[_UINT+1] = dAtoi( valBuffer );
  1141. }
  1142. _UINT++;
  1143. break;
  1144. case OP_LOADFIELD_FLT:
  1145. if(curObject)
  1146. floatStack[_FLT+1] = dAtof(curObject->getDataField(curField, curFieldArray));
  1147. else
  1148. {
  1149. // The field is not being retrieved from an object. Maybe it's
  1150. // a special accessor?
  1151. getFieldComponent( prevObject, prevField, prevFieldArray, curField, valBuffer );
  1152. floatStack[_FLT+1] = dAtof( valBuffer );
  1153. }
  1154. _FLT++;
  1155. break;
  1156. case OP_LOADFIELD_STR:
  1157. if(curObject)
  1158. {
  1159. val = curObject->getDataField(curField, curFieldArray);
  1160. STR.setStringValue( val );
  1161. }
  1162. else
  1163. {
  1164. // The field is not being retrieved from an object. Maybe it's
  1165. // a special accessor?
  1166. getFieldComponent( prevObject, prevField, prevFieldArray, curField, valBuffer );
  1167. STR.setStringValue( valBuffer );
  1168. }
  1169. break;
  1170. case OP_SAVEFIELD_UINT:
  1171. STR.setIntValue(intStack[_UINT]);
  1172. if(curObject)
  1173. curObject->setDataField(curField, curFieldArray, STR.getStringValue());
  1174. else
  1175. {
  1176. // The field is not being set on an object. Maybe it's
  1177. // a special accessor?
  1178. setFieldComponent( prevObject, prevField, prevFieldArray, curField );
  1179. prevObject = NULL;
  1180. }
  1181. break;
  1182. case OP_SAVEFIELD_FLT:
  1183. STR.setFloatValue(floatStack[_FLT]);
  1184. if(curObject)
  1185. curObject->setDataField(curField, curFieldArray, STR.getStringValue());
  1186. else
  1187. {
  1188. // The field is not being set on an object. Maybe it's
  1189. // a special accessor?
  1190. setFieldComponent( prevObject, prevField, prevFieldArray, curField );
  1191. prevObject = NULL;
  1192. }
  1193. break;
  1194. case OP_SAVEFIELD_STR:
  1195. if(curObject)
  1196. curObject->setDataField(curField, curFieldArray, STR.getStringValue());
  1197. else
  1198. {
  1199. // The field is not being set on an object. Maybe it's
  1200. // a special accessor?
  1201. setFieldComponent( prevObject, prevField, prevFieldArray, curField );
  1202. prevObject = NULL;
  1203. }
  1204. break;
  1205. case OP_STR_TO_UINT:
  1206. intStack[_UINT+1] = STR.getIntValue();
  1207. _UINT++;
  1208. break;
  1209. case OP_STR_TO_FLT:
  1210. floatStack[_FLT+1] = STR.getFloatValue();
  1211. _FLT++;
  1212. break;
  1213. case OP_STR_TO_NONE:
  1214. // This exists simply to deal with certain typecast situations.
  1215. break;
  1216. case OP_FLT_TO_UINT:
  1217. intStack[_UINT+1] = (S64)floatStack[_FLT];
  1218. _FLT--;
  1219. _UINT++;
  1220. break;
  1221. case OP_FLT_TO_STR:
  1222. STR.setFloatValue(floatStack[_FLT]);
  1223. _FLT--;
  1224. break;
  1225. case OP_FLT_TO_NONE:
  1226. _FLT--;
  1227. break;
  1228. case OP_UINT_TO_FLT:
  1229. floatStack[_FLT+1] = (F32)intStack[_UINT];
  1230. _UINT--;
  1231. _FLT++;
  1232. break;
  1233. case OP_UINT_TO_STR:
  1234. STR.setIntValue(intStack[_UINT]);
  1235. _UINT--;
  1236. break;
  1237. case OP_UINT_TO_NONE:
  1238. _UINT--;
  1239. break;
  1240. case OP_LOADIMMED_UINT:
  1241. intStack[_UINT+1] = code[ip++];
  1242. _UINT++;
  1243. break;
  1244. case OP_LOADIMMED_FLT:
  1245. floatStack[_FLT+1] = curFloatTable[code[ip]];
  1246. ip++;
  1247. _FLT++;
  1248. break;
  1249. case OP_TAG_TO_STR:
  1250. code[ip-1] = OP_LOADIMMED_STR;
  1251. // it's possible the string has already been converted
  1252. if(U8(curStringTable[code[ip]]) != StringTagPrefixByte)
  1253. {
  1254. U32 id = GameAddTaggedString(curStringTable + code[ip]);
  1255. dSprintf(curStringTable + code[ip] + 1, 7, "%d", id);
  1256. *(curStringTable + code[ip]) = StringTagPrefixByte;
  1257. }
  1258. case OP_LOADIMMED_STR:
  1259. STR.setStringValue(curStringTable + code[ip++]);
  1260. break;
  1261. case OP_DOCBLOCK_STR:
  1262. {
  1263. // If the first word of the doc is '\class' or '@class', then this
  1264. // is a namespace doc block, otherwise it is a function doc block.
  1265. const char* docblock = curStringTable + code[ip++];
  1266. const char* sansClass = dStrstr( docblock, "@class" );
  1267. if( !sansClass )
  1268. sansClass = dStrstr( docblock, "\\class" );
  1269. if( sansClass )
  1270. {
  1271. // Don't save the class declaration. Scan past the 'class'
  1272. // keyword and up to the first whitespace.
  1273. sansClass += 7;
  1274. S32 index = 0;
  1275. while( ( *sansClass != ' ' ) && ( *sansClass != '\n' ) && *sansClass && ( index < ( nsDocLength - 1 ) ) )
  1276. {
  1277. nsDocBlockClass[index++] = *sansClass;
  1278. sansClass++;
  1279. }
  1280. nsDocBlockClass[index] = '\0';
  1281. curNSDocBlock = sansClass + 1;
  1282. }
  1283. else
  1284. curFNDocBlock = docblock;
  1285. }
  1286. break;
  1287. case OP_LOADIMMED_IDENT:
  1288. STR.setStringValue(U32toSTE(code[ip++]));
  1289. break;
  1290. case OP_CALLFUNC_RESOLVE:
  1291. // This deals with a function that is potentially living in a namespace.
  1292. fnNamespace = U32toSTE(code[ip+1]);
  1293. fnName = U32toSTE(code[ip]);
  1294. // Try to look it up.
  1295. ns = Namespace::find(fnNamespace);
  1296. nsEntry = ns->lookup(fnName);
  1297. if(!nsEntry)
  1298. {
  1299. ip+= 3;
  1300. Con::warnf(ConsoleLogEntry::General,
  1301. "%s: Unable to find function %s%s%s",
  1302. getFileLine(ip-4), fnNamespace ? fnNamespace : "",
  1303. fnNamespace ? "::" : "", fnName);
  1304. STR.popFrame();
  1305. break;
  1306. }
  1307. // Now fall through to OP_CALLFUNC...
  1308. case OP_CALLFUNC:
  1309. {
  1310. // This routingId is set when we query the object as to whether
  1311. // it handles this method. It is set to an enum from the table
  1312. // above indicating whether it handles it on a component it owns
  1313. // or just on the object.
  1314. S32 routingId = 0;
  1315. fnName = U32toSTE(code[ip]);
  1316. //if this is called from inside a function, append the ip and codeptr
  1317. if( gEvalState.getStackDepth() > 0 )
  1318. {
  1319. gEvalState.getCurrentFrame().code = this;
  1320. gEvalState.getCurrentFrame().ip = ip - 1;
  1321. }
  1322. U32 callType = code[ip+2];
  1323. ip += 3;
  1324. STR.getArgcArgv(fnName, &callArgc, &callArgv);
  1325. const char *componentReturnValue = "";
  1326. if(callType == FuncCallExprNode::FunctionCall)
  1327. {
  1328. if( !nsEntry )
  1329. {
  1330. // We must not have come from OP_CALLFUNC_RESOLVE, so figure out
  1331. // our own entry.
  1332. nsEntry = Namespace::global()->lookup( fnName );
  1333. }
  1334. ns = NULL;
  1335. }
  1336. else if(callType == FuncCallExprNode::MethodCall)
  1337. {
  1338. saveObject = gEvalState.thisObject;
  1339. gEvalState.thisObject = Sim::findObject(callArgv[1]);
  1340. if(!gEvalState.thisObject)
  1341. {
  1342. // Go back to the previous saved object.
  1343. gEvalState.thisObject = saveObject;
  1344. Con::warnf(ConsoleLogEntry::General,"%s: Unable to find object: '%s' attempting to call function '%s'", getFileLine(ip-4), callArgv[1], fnName);
  1345. STR.popFrame();
  1346. break;
  1347. }
  1348. bool handlesMethod = gEvalState.thisObject->handlesConsoleMethod(fnName,&routingId);
  1349. if( handlesMethod && routingId == MethodOnComponent )
  1350. {
  1351. ICallMethod *pComponent = dynamic_cast<ICallMethod *>( gEvalState.thisObject );
  1352. if( pComponent )
  1353. componentReturnValue = pComponent->callMethodArgList( callArgc, callArgv, false );
  1354. }
  1355. ns = gEvalState.thisObject->getNamespace();
  1356. if(ns)
  1357. nsEntry = ns->lookup(fnName);
  1358. else
  1359. nsEntry = NULL;
  1360. }
  1361. else // it's a ParentCall
  1362. {
  1363. if(thisNamespace)
  1364. {
  1365. ns = thisNamespace->mParent;
  1366. if(ns)
  1367. nsEntry = ns->lookup(fnName);
  1368. else
  1369. nsEntry = NULL;
  1370. }
  1371. else
  1372. {
  1373. ns = NULL;
  1374. nsEntry = NULL;
  1375. }
  1376. }
  1377. Namespace::Entry::CallbackUnion * nsCb = NULL;
  1378. const char * nsUsage = NULL;
  1379. if (nsEntry)
  1380. {
  1381. nsCb = &nsEntry->cb;
  1382. nsUsage = nsEntry->mUsage;
  1383. routingId = 0;
  1384. }
  1385. if(!nsEntry || noCalls)
  1386. {
  1387. if(!noCalls && !( routingId == MethodOnComponent ) )
  1388. {
  1389. Con::warnf(ConsoleLogEntry::General,"%s: Unknown command %s.", getFileLine(ip-4), fnName);
  1390. if(callType == FuncCallExprNode::MethodCall)
  1391. {
  1392. Con::warnf(ConsoleLogEntry::General, " Object %s(%d) %s",
  1393. gEvalState.thisObject->getName() ? gEvalState.thisObject->getName() : "",
  1394. gEvalState.thisObject->getId(), Con::getNamespaceList(ns) );
  1395. }
  1396. }
  1397. STR.popFrame();
  1398. if( routingId == MethodOnComponent )
  1399. STR.setStringValue( componentReturnValue );
  1400. else
  1401. STR.setStringValue( "" );
  1402. break;
  1403. }
  1404. if(nsEntry->mType == Namespace::Entry::ConsoleFunctionType)
  1405. {
  1406. const char *ret = "";
  1407. if(nsEntry->mFunctionOffset)
  1408. ret = nsEntry->mCode->exec(nsEntry->mFunctionOffset, fnName, nsEntry->mNamespace, callArgc, callArgv, false, nsEntry->mPackage);
  1409. STR.popFrame();
  1410. STR.setStringValue(ret);
  1411. }
  1412. else
  1413. {
  1414. const char* nsName = ns? ns->mName: "";
  1415. #ifndef TORQUE_DEBUG
  1416. // [tom, 12/13/2006] This stops tools functions from working in the console,
  1417. // which is useful behavior when debugging so I'm ifdefing this out for debug builds.
  1418. if(nsEntry->mToolOnly && ! Con::isCurrentScriptToolScript())
  1419. {
  1420. Con::errorf(ConsoleLogEntry::Script, "%s: %s::%s - attempting to call tools only function from outside of tools.", getFileLine(ip-4), nsName, fnName);
  1421. }
  1422. else
  1423. #endif
  1424. if((nsEntry->mMinArgs && S32(callArgc) < nsEntry->mMinArgs) || (nsEntry->mMaxArgs && S32(callArgc) > nsEntry->mMaxArgs))
  1425. {
  1426. Con::warnf(ConsoleLogEntry::Script, "%s: %s::%s - wrong number of arguments (got %i, expected min %i and max %i).",
  1427. getFileLine(ip-4), nsName, fnName,
  1428. callArgc, nsEntry->mMinArgs, nsEntry->mMaxArgs);
  1429. Con::warnf(ConsoleLogEntry::Script, "%s: usage: %s", getFileLine(ip-4), nsEntry->mUsage);
  1430. STR.popFrame();
  1431. }
  1432. else
  1433. {
  1434. switch(nsEntry->mType)
  1435. {
  1436. case Namespace::Entry::StringCallbackType:
  1437. {
  1438. const char *ret = nsEntry->cb.mStringCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1439. STR.popFrame();
  1440. if(ret != STR.getStringValue())
  1441. STR.setStringValue(ret);
  1442. else
  1443. STR.setLen(dStrlen(ret));
  1444. break;
  1445. }
  1446. case Namespace::Entry::IntCallbackType:
  1447. {
  1448. S32 result = nsEntry->cb.mIntCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1449. STR.popFrame();
  1450. if(code[ip] == OP_STR_TO_UINT)
  1451. {
  1452. ip++;
  1453. intStack[++_UINT] = result;
  1454. break;
  1455. }
  1456. else if(code[ip] == OP_STR_TO_FLT)
  1457. {
  1458. ip++;
  1459. floatStack[++_FLT] = result;
  1460. break;
  1461. }
  1462. else if(code[ip] == OP_STR_TO_NONE)
  1463. ip++;
  1464. else
  1465. STR.setIntValue(result);
  1466. break;
  1467. }
  1468. case Namespace::Entry::FloatCallbackType:
  1469. {
  1470. F64 result = nsEntry->cb.mFloatCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1471. STR.popFrame();
  1472. if(code[ip] == OP_STR_TO_UINT)
  1473. {
  1474. ip++;
  1475. intStack[++_UINT] = (S64)result;
  1476. break;
  1477. }
  1478. else if(code[ip] == OP_STR_TO_FLT)
  1479. {
  1480. ip++;
  1481. floatStack[++_FLT] = result;
  1482. break;
  1483. }
  1484. else if(code[ip] == OP_STR_TO_NONE)
  1485. ip++;
  1486. else
  1487. STR.setFloatValue(result);
  1488. break;
  1489. }
  1490. case Namespace::Entry::VoidCallbackType:
  1491. nsEntry->cb.mVoidCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1492. if( code[ ip ] != OP_STR_TO_NONE && Con::getBoolVariable( "$Con::warnVoidAssignment", true ) )
  1493. Con::warnf(ConsoleLogEntry::General, "%s: Call to %s in %s uses result of void function call.", getFileLine(ip-4), fnName, functionName);
  1494. STR.popFrame();
  1495. STR.setStringValue("");
  1496. break;
  1497. case Namespace::Entry::BoolCallbackType:
  1498. {
  1499. bool result = nsEntry->cb.mBoolCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1500. STR.popFrame();
  1501. if(code[ip] == OP_STR_TO_UINT)
  1502. {
  1503. ip++;
  1504. intStack[++_UINT] = result;
  1505. break;
  1506. }
  1507. else if(code[ip] == OP_STR_TO_FLT)
  1508. {
  1509. ip++;
  1510. floatStack[++_FLT] = result;
  1511. break;
  1512. }
  1513. else if(code[ip] == OP_STR_TO_NONE)
  1514. ip++;
  1515. else
  1516. STR.setIntValue(result);
  1517. break;
  1518. }
  1519. }
  1520. }
  1521. }
  1522. if(callType == FuncCallExprNode::MethodCall)
  1523. gEvalState.thisObject = saveObject;
  1524. break;
  1525. }
  1526. case OP_ADVANCE_STR:
  1527. STR.advance();
  1528. break;
  1529. case OP_ADVANCE_STR_APPENDCHAR:
  1530. STR.advanceChar(code[ip++]);
  1531. break;
  1532. case OP_ADVANCE_STR_COMMA:
  1533. STR.advanceChar('_');
  1534. break;
  1535. case OP_ADVANCE_STR_NUL:
  1536. STR.advanceChar(0);
  1537. break;
  1538. case OP_REWIND_STR:
  1539. STR.rewind();
  1540. break;
  1541. case OP_TERMINATE_REWIND_STR:
  1542. STR.rewindTerminate();
  1543. break;
  1544. case OP_COMPARE_STR:
  1545. intStack[++_UINT] = STR.compare();
  1546. break;
  1547. case OP_PUSH:
  1548. STR.push();
  1549. break;
  1550. case OP_PUSH_FRAME:
  1551. STR.pushFrame();
  1552. break;
  1553. case OP_ASSERT:
  1554. {
  1555. if( !intStack[_UINT--] )
  1556. {
  1557. const char *message = curStringTable + code[ip];
  1558. U32 breakLine, inst;
  1559. findBreakLine( ip - 1, breakLine, inst );
  1560. if ( PlatformAssert::processAssert( PlatformAssert::Fatal,
  1561. name ? name : "eval",
  1562. breakLine,
  1563. message ) )
  1564. {
  1565. if ( TelDebugger && TelDebugger->isConnected() && breakLine > 0 )
  1566. {
  1567. TelDebugger->breakProcess();
  1568. }
  1569. else
  1570. Platform::debugBreak();
  1571. }
  1572. }
  1573. ip++;
  1574. break;
  1575. }
  1576. case OP_BREAK:
  1577. {
  1578. //append the ip and codeptr before managing the breakpoint!
  1579. AssertFatal( gEvalState.getStackDepth() > 0, "Empty eval stack on break!");
  1580. gEvalState.getCurrentFrame().code = this;
  1581. gEvalState.getCurrentFrame().ip = ip - 1;
  1582. U32 breakLine;
  1583. findBreakLine(ip-1, breakLine, instruction);
  1584. if(!breakLine)
  1585. goto breakContinue;
  1586. TelDebugger->executionStopped(this, breakLine);
  1587. goto breakContinue;
  1588. }
  1589. case OP_ITER_BEGIN_STR:
  1590. {
  1591. iterStack[ _ITER ].mIsStringIter = true;
  1592. /* fallthrough */
  1593. }
  1594. case OP_ITER_BEGIN:
  1595. {
  1596. StringTableEntry varName = U32toSTE( code[ ip ] );
  1597. U32 failIp = code[ ip + 1 ];
  1598. IterStackRecord& iter = iterStack[ _ITER ];
  1599. iter.mVariable = gEvalState.getCurrentFrame().add( varName );
  1600. if( iter.mIsStringIter )
  1601. {
  1602. iter.mData.mStr.mString = STR.getStringValue();
  1603. iter.mData.mStr.mIndex = 0;
  1604. }
  1605. else
  1606. {
  1607. // Look up the object.
  1608. SimSet* set;
  1609. if( !Sim::findObject( STR.getStringValue(), set ) )
  1610. {
  1611. Con::errorf( ConsoleLogEntry::General, "No SimSet object '%s'", STR.getStringValue() );
  1612. Con::errorf( ConsoleLogEntry::General, "Did you mean to use 'foreach$' instead of 'foreach'?" );
  1613. ip = failIp;
  1614. continue;
  1615. }
  1616. // Set up.
  1617. iter.mData.mObj.mSet = set;
  1618. iter.mData.mObj.mIndex = 0;
  1619. }
  1620. _ITER ++;
  1621. iterDepth ++;
  1622. STR.push();
  1623. ip += 2;
  1624. break;
  1625. }
  1626. case OP_ITER:
  1627. {
  1628. U32 breakIp = code[ ip ];
  1629. IterStackRecord& iter = iterStack[ _ITER - 1 ];
  1630. if( iter.mIsStringIter )
  1631. {
  1632. const char* str = iter.mData.mStr.mString;
  1633. U32 startIndex = iter.mData.mStr.mIndex;
  1634. U32 endIndex = startIndex;
  1635. // Break if at end.
  1636. if( !str[ startIndex ] )
  1637. {
  1638. ip = breakIp;
  1639. continue;
  1640. }
  1641. // Find right end of current component.
  1642. if( !dIsspace( str[ endIndex ] ) )
  1643. do ++ endIndex;
  1644. while( str[ endIndex ] && !dIsspace( str[ endIndex ] ) );
  1645. // Extract component.
  1646. if( endIndex != startIndex )
  1647. {
  1648. char savedChar = str[ endIndex ];
  1649. const_cast< char* >( str )[ endIndex ] = '\0'; // We are on the string stack so this is okay.
  1650. iter.mVariable->setStringValue( &str[ startIndex ] );
  1651. const_cast< char* >( str )[ endIndex ] = savedChar;
  1652. }
  1653. else
  1654. iter.mVariable->setStringValue( "" );
  1655. // Skip separator.
  1656. if( str[ endIndex ] != '\0' )
  1657. ++ endIndex;
  1658. iter.mData.mStr.mIndex = endIndex;
  1659. }
  1660. else
  1661. {
  1662. U32 index = iter.mData.mObj.mIndex;
  1663. SimSet* set = iter.mData.mObj.mSet;
  1664. if( index >= set->size() )
  1665. {
  1666. ip = breakIp;
  1667. continue;
  1668. }
  1669. iter.mVariable->setIntValue( set->at( index )->getId() );
  1670. iter.mData.mObj.mIndex = index + 1;
  1671. }
  1672. ++ ip;
  1673. break;
  1674. }
  1675. case OP_ITER_END:
  1676. {
  1677. -- _ITER;
  1678. -- iterDepth;
  1679. STR.rewind();
  1680. iterStack[ _ITER ].mIsStringIter = false;
  1681. break;
  1682. }
  1683. case OP_INVALID:
  1684. default:
  1685. // error!
  1686. goto execFinished;
  1687. }
  1688. }
  1689. execFinished:
  1690. if ( telDebuggerOn && setFrame < 0 )
  1691. TelDebugger->popStackFrame();
  1692. if ( popFrame )
  1693. gEvalState.popFrame();
  1694. if(argv)
  1695. {
  1696. if(gEvalState.traceOn)
  1697. {
  1698. traceBuffer[0] = 0;
  1699. dStrcat(traceBuffer, "Leaving ");
  1700. if(packageName)
  1701. {
  1702. dStrcat(traceBuffer, "[");
  1703. dStrcat(traceBuffer, packageName);
  1704. dStrcat(traceBuffer, "]");
  1705. }
  1706. if(thisNamespace && thisNamespace->mName)
  1707. {
  1708. dSprintf(traceBuffer + dStrlen(traceBuffer), sizeof(traceBuffer) - dStrlen(traceBuffer),
  1709. "%s::%s() - return %s", thisNamespace->mName, thisFunctionName, STR.getStringValue());
  1710. }
  1711. else
  1712. {
  1713. dSprintf(traceBuffer + dStrlen(traceBuffer), sizeof(traceBuffer) - dStrlen(traceBuffer),
  1714. "%s() - return %s", thisFunctionName, STR.getStringValue());
  1715. }
  1716. Con::printf("%s", traceBuffer);
  1717. }
  1718. }
  1719. else
  1720. {
  1721. delete[] globalStrings;
  1722. globalStringsMaxLen = 0;
  1723. delete[] globalFloats;
  1724. globalStrings = NULL;
  1725. globalFloats = NULL;
  1726. }
  1727. smCurrentCodeBlock = saveCodeBlock;
  1728. if(saveCodeBlock && saveCodeBlock->name)
  1729. {
  1730. Con::gCurrentFile = saveCodeBlock->name;
  1731. Con::gCurrentRoot = saveCodeBlock->modPath;
  1732. }
  1733. decRefCount();
  1734. #ifdef TORQUE_DEBUG
  1735. AssertFatal(!(STR.mStartStackSize > stackStart), "String stack not popped enough in script exec");
  1736. AssertFatal(!(STR.mStartStackSize < stackStart), "String stack popped too much in script exec");
  1737. #endif
  1738. return STR.getStringValue();
  1739. }
  1740. //------------------------------------------------------------