Skip to content

Commit

Permalink
feat: id & nick now reflection properties that may throw an excep…
Browse files Browse the repository at this point in the history
…tion

 Removes the special treatment from Reflection Lua Implementation, instead they are normal properties that may throw an exception if called on a non-network-component.
  • Loading branch information
Panakotta00 committed Jul 24, 2024
1 parent ffb4eef commit c7aa0c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "FINGlobalRegisterHelper.h"

#include "Computer/FINComputerGPUT1.h"
#include "Network/FINNetworkUtils.h"
#include "Network/FINFuture.h"
#include "Network/FINNetworkConnectionComponent.h"
#include "Utils/FINTargetPoint.h"
Expand Down Expand Up @@ -64,6 +65,7 @@
#include "Computer/FINComputerGPUT2.h"
#include "Computer/FINComputerSubsystem.h"
#include "FicsItKernel/Logging.h"
#include "Network/FINNetworkComponent.h"
#include "WheeledVehicles/FGTargetPointLinkedList.h"
#include "WheeledVehicles/FGWheeledVehicle.h"

Expand Down Expand Up @@ -598,6 +600,29 @@ class FStaticReflectionSourceHelper {
};

BeginClass(UObject, "Object", "Object", "The base class of every object.")
BeginProp(RString, nick, "Nick", "**Only available for Network Components!** Allows access to the Network Components Nick.") {
UObject* NetworkHandler = UFINNetworkUtils::FindNetworkComponentFromObject(self);
if (NetworkHandler) {
Return IFINNetworkComponent::Execute_GetNick(NetworkHandler);
} else {
throw FFINException("Not a network component!");
}
} PropSet() {
UObject* NetworkHandler = UFINNetworkUtils::FindNetworkComponentFromObject(self);
if (NetworkHandler) {
IFINNetworkComponent::Execute_SetNick(NetworkHandler, Val);
} else {
throw FFINException("Not a network component!");
}
} EndProp()
BeginProp(RString, id, "ID", "**Only available for Network Components!** Allows access to the Network Components UUID.") {
UObject* NetworkHandler = UFINNetworkUtils::FindNetworkComponentFromObject(self);
if (NetworkHandler) {
Return IFINNetworkComponent::Execute_GetID(NetworkHandler).ToString();
} else {
throw FFINException("Not a network component!");
}
} EndProp()
BeginProp(RInt, hash, "Hash", "A Hash of this object. This is a value that nearly uniquely identifies this object.") {
Return (int64)GetTypeHash(self);
} EndProp()
Expand Down
21 changes: 0 additions & 21 deletions Source/FicsItNetworksLua/Private/FINLua/Reflection/LuaObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,6 @@ namespace FINLua {
FLuaObject* LuaObject = luaFIN_checkLuaObject(L, thisIndex, nullptr);
FString MemberName = luaFIN_toFString(L, nameIndex);

UObject* NetworkHandler = UFINNetworkUtils::FindNetworkComponentFromObject(*LuaObject->Object);
if (NetworkHandler) {
if (MemberName == "id") {
lua_pushstring(L, TCHAR_TO_UTF8(*IFINNetworkComponent::Execute_GetID(NetworkHandler).ToString()));
return 1;
}
if (MemberName == "nick") {
lua_pushstring(L, TCHAR_TO_UTF8(*IFINNetworkComponent::Execute_GetNick(NetworkHandler)));
return 1;
}
}

FFINExecutionContext Context(LuaObject->Object);
return luaFIN_pushFunctionOrGetProperty(L, thisIndex, LuaObject->Type, MemberName, FIN_Func_MemberFunc, FIN_Prop_Attrib, Context, true);
}
Expand All @@ -124,15 +112,6 @@ namespace FINLua {
FLuaObject* LuaObject = luaFIN_checkLuaObject(L, thisIndex, nullptr);
FString MemberName = luaFIN_toFString(L, nameIndex);

UObject* NetworkHandler = UFINNetworkUtils::FindNetworkComponentFromObject(*LuaObject->Object);
if (NetworkHandler) {
if (MemberName == "nick") {
FString nick = luaFIN_toFString(L, valueIndex);
IFINNetworkComponent::Execute_SetNick(NetworkHandler, nick);
return 0;
}
}

FFINExecutionContext Context(LuaObject->Object);
luaFIN_tryExecuteSetProperty(L, thisIndex, LuaObject->Type, MemberName, FIN_Prop_Attrib, Context, valueIndex, true);
return 0;
Expand Down

0 comments on commit c7aa0c0

Please sign in to comment.