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

Function GetFieldInternal

Plugins/UnLua/Source/UnLua/Private/LuaCore.cpp:995–1060  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

993}
994
995static void GetFieldInternal(lua_State* L)
996{
997 lua_pop(L, 1);
998
999 lua_pushstring(L, "__name");
1000 auto Type = lua_rawget(L, -2);
1001 check(Type == LUA_TSTRING);
1002
1003 const char* ClassName = lua_tostring(L, -1);
1004 const char* FieldName = lua_tostring(L, 2);
1005
1006 lua_pop(L, 1);
1007
1008 // TODO: refactor
1009 const auto Env = UnLua::FLuaEnv::FindEnv(L);
1010 const auto Registry = Env->GetClassRegistry();
1011 FClassDesc* ClassDesc = Registry->Register(ClassName);
1012 TSharedPtr<FFieldDesc> Field = ClassDesc->RegisterField(Env, FieldName, ClassDesc);
1013 if (Field && Field->IsValid())
1014 {
1015 bool bCached = false;
1016 bool bInherited = Field->IsInherited();
1017 if (bInherited)
1018 {
1019 FString SuperStructName = Field->GetOuterName();
1020 const auto Pushed = Registry->PushMetatable(L, TCHAR_TO_UTF8(*SuperStructName));
1021 check(Pushed);
1022 lua_pushvalue(L, 2);
1023 Type = lua_rawget(L, -2);
1024 bCached = Type != LUA_TNIL;
1025 if (!bCached)
1026 {
1027 lua_pop(L, 1);
1028 }
1029 }
1030
1031 if (!bCached)
1032 {
1033 PushField(L, Field); // Property / closure
1034 lua_pushvalue(L, 2); // key
1035 lua_pushvalue(L, -2); // Property / closure
1036 lua_rawset(L, -4);
1037 }
1038 if (bInherited)
1039 {
1040 lua_remove(L, -2);
1041 lua_pushvalue(L, 2); // key
1042 lua_pushvalue(L, -2); // Property / closure
1043 lua_rawset(L, -4);
1044 }
1045 }
1046 else
1047 {
1048 if (ClassDesc->IsClass())
1049 {
1050 luaL_getmetatable(L, "UClass");
1051 lua_pushvalue(L, 2); // push key
1052 lua_rawget(L, -2);

Callers 1

GetFieldFunction · 0.85

Calls 14

lua_pushstringFunction · 0.85
lua_rawgetFunction · 0.85
checkFunction · 0.85
lua_pushvalueFunction · 0.85
PushFieldFunction · 0.85
lua_rawsetFunction · 0.85
lua_pushnilFunction · 0.85
RegisterFieldMethod · 0.80
IsInheritedMethod · 0.80
GetOuterNameMethod · 0.80
PushMetatableMethod · 0.80
IsClassMethod · 0.80

Tested by

no test coverage detected