MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / GetVariable

Method GetVariable

emmy_debugger/src/debugger/emmy_debugger.cpp:364–535  ·  view source on GitHub ↗

algorithm optimization

Source from the content-addressed store, hash-verified

362#endif
363// algorithm optimization
364void 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 }

Callers 1

metaQueryFunction · 0.80

Calls 15

CallMetaFunctionFunction · 0.85
ToPointerFunction · 0.85
DisplayFunctionFunction · 0.85
sizeMethod · 0.80
QueryVariableCustomMethod · 0.80
QueryVariableMethod · 0.80
AllocMethod · 0.80
GetArenaMethod · 0.80
push_backMethod · 0.80
lua_gettopFunction · 0.50
lua_absindexFunction · 0.50
lua_typeFunction · 0.50

Tested by

no test coverage detected