MCPcopy Create free account
hub / github.com/Tencent/UnLua / GetStackVariables

Function GetStackVariables

Plugins/UnLua/Source/UnLua/Private/UnLuaDebugBase.cpp:605–661  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

603
604
605 bool GetStackVariables(lua_State *L, int32 StackLevel, TArray<FLuaVariable> &LocalVariables, TArray<FLuaVariable> &Upvalues, int32 Level)
606 {
607 if (!L)
608 {
609 return false;
610 }
611 lua_Debug ar;
612 if (!lua_getstack(L, StackLevel, &ar))
613 {
614 return false;
615 }
616 if (!lua_getinfo(L, "nSlu", &ar))
617 {
618 return false;
619 }
620
621 for (int32 i = 1; ; ++i)
622 {
623 const char *VarName = lua_getlocal(L, &ar, i);
624 if (!VarName)
625 {
626 break;
627 }
628 if (VarName[0] == '(')
629 {
630 lua_pop(L, 1);
631 continue;
632 }
633 LocalVariables.AddDefaulted();
634 FLuaVariable &Variable = LocalVariables.Top();
635 Variable.Key = UTF8_TO_TCHAR(VarName);
636 Variable.Value.Depth = 0;
637 Variable.Value.Build(L, -1, Level);
638 lua_pop(L, 1);
639 }
640
641 if (lua_getinfo(L, "f", &ar))
642 {
643 int32 FunctionIdx = lua_gettop(L);
644 for (int32 i = 1; ; ++i)
645 {
646 const char *UpvalueName = lua_getupvalue(L, FunctionIdx, i);
647 if (!UpvalueName)
648 {
649 break;
650 }
651 Upvalues.AddDefaulted();
652 FLuaVariable &Upvalue = Upvalues.Top();
653 Upvalue.Key = UTF8_TO_TCHAR(UpvalueName);
654 Upvalue.Value.Depth = 0;
655 Upvalue.Value.Build(L, -1, Level);
656 lua_pop(L, 1);
657 }
658 }
659
660 return true;
661 }
662

Callers

nothing calls this directly

Calls 8

lua_getstackFunction · 0.85
lua_getinfoFunction · 0.85
lua_getlocalFunction · 0.85
lua_gettopFunction · 0.85
lua_getupvalueFunction · 0.85
AddDefaultedMethod · 0.80
TopMethod · 0.80
BuildMethod · 0.80

Tested by

no test coverage detected