| 993 | } |
| 994 | |
| 995 | static 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); |
no test coverage detected