| 857 | } |
| 858 | |
| 859 | void TelnetDebugger::evaluateExpression(const char *tag, S32 frame, const char *evalBuffer) |
| 860 | { |
| 861 | // Make sure we're passing a valid frame to the eval. |
| 862 | if ( frame > gEvalState.getStackDepth() ) |
| 863 | frame = gEvalState.getStackDepth() - 1; |
| 864 | if ( frame < 0 ) |
| 865 | frame = 0; |
| 866 | |
| 867 | // Local variables use their own memory management and can't be queried by just executing |
| 868 | // TorqueScript, we have to go digging into the interpreter. |
| 869 | S32 evalBufferLen = dStrlen(evalBuffer); |
| 870 | bool isEvaluatingLocalVariable = evalBufferLen > 0 && evalBuffer[0] == '%'; |
| 871 | if (isEvaluatingLocalVariable) |
| 872 | { |
| 873 | // See calculation of current frame in pushing a reference frame for console exec, we need access |
| 874 | // to the proper scope. |
| 875 | //frame = gEvalState.getTopOfStack() - frame - 1; |
| 876 | S32 stackIndex = gEvalState.getTopOfStack() - frame - 1; |
| 877 | |
| 878 | const char* format = "EVALOUT %s %s\r\n"; |
| 879 | |
| 880 | gEvalState.pushDebugFrame(stackIndex); |
| 881 | |
| 882 | Dictionary& stackFrame = gEvalState.getCurrentFrame(); |
| 883 | StringTableEntry functionName = stackFrame.scopeName; |
| 884 | StringTableEntry namespaceName = stackFrame.scopeNamespace->mName; |
| 885 | StringTableEntry varToLookup = StringTable->insert(evalBuffer); |
| 886 | |
| 887 | S32 registerId = stackFrame.code->variableRegisterTable.lookup(namespaceName, functionName, varToLookup); |
| 888 | |
| 889 | if (registerId == -1) |
| 890 | { |
| 891 | // ERROR, can't read the variable! |
| 892 | send("EVALOUT \"\" \"\""); |
| 893 | return; |
| 894 | } |
| 895 | |
| 896 | const char* varResult = gEvalState.getLocalStringVariable(registerId); |
| 897 | |
| 898 | gEvalState.popFrame(); |
| 899 | |
| 900 | S32 len = dStrlen(format) + dStrlen(tag) + dStrlen(varResult); |
| 901 | char* buffer = new char[len]; |
| 902 | dSprintf(buffer, len, format, tag, varResult[0] ? varResult : "\"\""); |
| 903 | |
| 904 | send(buffer); |
| 905 | delete[] buffer; |
| 906 | |
| 907 | return; |
| 908 | } |
| 909 | |
| 910 | // Build a buffer just big enough for this eval. |
| 911 | const char* format = "return %s;"; |
| 912 | dsize_t len = dStrlen( format ) + dStrlen( evalBuffer ); |
| 913 | char* buffer = new char[ len ]; |
| 914 | dSprintf( buffer, len, format, evalBuffer ); |
| 915 | |
| 916 | // Execute the eval. |
nothing calls this directly
no test coverage detected