algorithm optimization
| 362 | #endif |
| 363 | // algorithm optimization |
| 364 | void Debugger::GetVariable(lua_State *L, Idx<Variable> variable, int index, int depth, bool queryHelper) { |
| 365 | if (!L) { |
| 366 | L = currentL; |
| 367 | } |
| 368 | |
| 369 | if (!L) { |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | // 如果没有计算深度则不予计算 |
| 374 | if (depth <= 0) { |
| 375 | return; |
| 376 | } |
| 377 | |
| 378 | const int topIndex = lua_gettop(L); |
| 379 | index = lua_absindex(L, index); |
| 380 | CacheValue(index, variable); |
| 381 | const int type = lua_type(L, index); |
| 382 | const char *typeName = lua_typename(L, type); |
| 383 | variable->valueTypeName = typeName; |
| 384 | variable->valueType = type; |
| 385 | |
| 386 | if (queryHelper) { |
| 387 | if (displayCustomTypeInfo && type >= 0 && type < registeredTypes.size() && registeredTypes.test(type) |
| 388 | && manager->extension.QueryVariableCustom(L, variable, typeName, index, depth)) { |
| 389 | return; |
| 390 | } |
| 391 | else if ((type == LUA_TTABLE || type == LUA_TUSERDATA || type == LUA_TFUNCTION) |
| 392 | && manager->extension.QueryVariable(L, variable, typeName, index, depth)) { |
| 393 | return; |
| 394 | } |
| 395 | } |
| 396 | switch (type) { |
| 397 | case LUA_TNIL: { |
| 398 | variable->value = "nil"; |
| 399 | break; |
| 400 | } |
| 401 | case LUA_TNUMBER: { |
| 402 | variable->value = lua_tostring(L, index); |
| 403 | break; |
| 404 | } |
| 405 | case LUA_TBOOLEAN: { |
| 406 | const bool v = lua_toboolean(L, index); |
| 407 | variable->value = v ? "true" : "false"; |
| 408 | break; |
| 409 | } |
| 410 | case LUA_TSTRING: { |
| 411 | variable->value = lua_tostring(L, index); |
| 412 | break; |
| 413 | } |
| 414 | case LUA_TUSERDATA: { |
| 415 | auto *string = lua_tostring(L, index); |
| 416 | if (string == nullptr) { |
| 417 | int result; |
| 418 | if (CallMetaFunction(L, topIndex, "__tostring", 1, result) && result == 0) { |
| 419 | string = lua_tostring(L, -1); |
| 420 | lua_pop(L, 1); |
| 421 | } |
no test coverage detected