host thread
| 927 | |
| 928 | // host thread |
| 929 | bool Debugger::DoEval(std::shared_ptr<EvalContext> evalContext) { |
| 930 | if (!currentL || !evalContext) { |
| 931 | return false; |
| 932 | } |
| 933 | |
| 934 | auto L = currentL; |
| 935 | |
| 936 | int innerLevel = evalContext->stackLevel; |
| 937 | |
| 938 | while (L != nullptr) { |
| 939 | int level = LastLevel(L); |
| 940 | if (innerLevel > level) { |
| 941 | innerLevel -= level; |
| 942 | L = manager->extension.QueryParentThread(L); |
| 943 | } else { |
| 944 | break; |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | if (L == nullptr) { |
| 949 | return false; |
| 950 | } |
| 951 | |
| 952 | //auto* const L = L; |
| 953 | // From "cacheId" |
| 954 | if (evalContext->cacheId > 0) { |
| 955 | lua_getfield(L, LUA_REGISTRYINDEX, CACHE_TABLE_NAME);// 1: cacheTable|nil |
| 956 | if (lua_type(L, -1) == LUA_TTABLE) { |
| 957 | lua_getfield(L, -1, std::to_string(evalContext->cacheId).c_str());// 1: cacheTable, 2: value |
| 958 | SetVariableArena(evalContext->result.GetArena()); |
| 959 | GetVariable(L, evalContext->result, -1, evalContext->depth); |
| 960 | ClearVariableArenaRef(); |
| 961 | lua_pop(L, 2); |
| 962 | return true; |
| 963 | } |
| 964 | lua_pop(L, 1); |
| 965 | } |
| 966 | // LOAD AS "return expr" |
| 967 | std::string statement = "return "; |
| 968 | if (evalContext->setValue) { |
| 969 | statement = evalContext->expr + " = " + evalContext->value + " return " + evalContext->expr; |
| 970 | } else { |
| 971 | statement.append(evalContext->expr); |
| 972 | } |
| 973 | |
| 974 | // 如果是 aaa:bbbb 则纠正为aaa.bbbb |
| 975 | int r = luaL_loadstring(L, statement.c_str()); |
| 976 | if (r == LUA_ERRSYNTAX) { |
| 977 | // 尝试将 : 替换为 . 后重新加载 |
| 978 | std::string correctedExpr = evalContext->expr; |
| 979 | size_t colonPos = correctedExpr.find(':'); |
| 980 | if (colonPos != std::string::npos) { |
| 981 | correctedExpr[colonPos] = '.'; |
| 982 | std::string correctedStatement = "return "; |
| 983 | if (evalContext->setValue) { |
| 984 | correctedStatement = correctedExpr + " = " + evalContext->value + " return " + correctedExpr; |
| 985 | } else { |
| 986 | correctedStatement.append(correctedExpr); |
nothing calls this directly
no test coverage detected