Skip to content

Commit

Permalink
fix: Nick change by code
Browse files Browse the repository at this point in the history
  • Loading branch information
Panakotta00 committed Jun 29, 2024
1 parent 687ef9c commit 9c2b2ec
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions Source/FicsItNetworksLua/Private/FINLua/LuaObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FINLua {
Type = FFINReflection::Get()->FindClass(Object.GetUnderlyingPtr()->GetClass());
Kernel->AddReferencer(this, &CollectReferences);
}

FLuaObject::FLuaObject(const FLuaObject& Other) : Type(Other.Type), Object(Other.Object), Kernel(Other.Kernel) {
Kernel->AddReferencer(this, &CollectReferences);
}
Expand All @@ -22,15 +22,15 @@ namespace FINLua {
void FLuaObject::CollectReferences(void* Obj, FReferenceCollector& Collector) {
static_cast<FLuaObject*>(Obj)->Object.AddStructReferencedObjects(Collector);
}

int luaObjectEQ(lua_State* L) {
FLuaObject* LuaObject1 = luaFIN_toLuaObject(L, 1, nullptr);
FLuaObject* LuaObject2 = luaFIN_toLuaObject(L, 2, nullptr);
if (!LuaObject1 || !LuaObject2) {
lua_pushboolean(L, false);
return UFINLuaProcessor::luaAPIReturn(L, 1);
}

lua_pushboolean(L, GetTypeHash(LuaObject1->Object) == GetTypeHash(LuaObject2->Object));
return UFINLuaProcessor::luaAPIReturn(L, 1);
}
Expand All @@ -42,7 +42,7 @@ namespace FINLua {
lua_pushboolean(L, false);
return UFINLuaProcessor::luaAPIReturn(L, 1);
}

lua_pushboolean(L, GetTypeHash(LuaObject1->Object) < GetTypeHash(LuaObject2->Object));
return UFINLuaProcessor::luaAPIReturn(L, 1);
}
Expand All @@ -54,7 +54,7 @@ namespace FINLua {
lua_pushboolean(L, false);
return UFINLuaProcessor::luaAPIReturn(L, 1);
}

lua_pushboolean(L, GetTypeHash(LuaObject1->Object) <= GetTypeHash(LuaObject2->Object));
return UFINLuaProcessor::luaAPIReturn(L, 1);
}
Expand All @@ -63,7 +63,7 @@ namespace FINLua {
ZoneScoped;
const int thisIndex = 1;
const int nameIndex = 2;

FLuaObject* LuaObject = luaFIN_checkLuaObject(L, thisIndex, nullptr);
FString MemberName = luaFIN_toFString(L, nameIndex);

Expand All @@ -82,17 +82,26 @@ namespace FINLua {
FFINExecutionContext Context(LuaObject->Object);
return luaFIN_pushFunctionOrGetProperty(L, thisIndex, LuaObject->Type, MemberName, FIN_Func_MemberFunc, FIN_Prop_Attrib, Context, true);
}

int luaObjectNewIndex(lua_State* L) {
ZoneScoped;

const int thisIndex = 1;
const int nameIndex = 2;
const int valueIndex = 3;

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 All @@ -108,15 +117,15 @@ namespace FINLua {
UFINLuaProcessor* Processor = UFINLuaProcessor::luaGetProcessor(L);
FFINLuaProcessorStateStorage& Storage = Processor->StateStorage;
FFINNetworkTrace Object = Storage.GetTrace(luaL_checkinteger(L, lua_upvalueindex(1)));

luaFIN_pushObject(L, Object);

return 1;
}

int luaObjectPersist(lua_State* L) {
FLuaObject* LuaObject = luaFIN_checkLuaObject(L, 1, nullptr);

UFINLuaProcessor* Processor = UFINLuaProcessor::luaGetProcessor(L);
FFINLuaProcessorStateStorage& Storage = Processor->StateStorage;
lua_pushinteger(L, Storage.Add(LuaObject->Object));
Expand All @@ -131,7 +140,7 @@ namespace FINLua {
LuaObject->~FLuaObject();
return 0;
}

static const luaL_Reg luaObjectMetatable[] = {
{"__eq", luaObjectEQ},
{"__lt", luaObjectLt},
Expand All @@ -143,14 +152,14 @@ namespace FINLua {
{"__gc", luaObjectGC},
{nullptr, nullptr}
};

void luaFIN_pushObject(lua_State* L, const FFINNetworkTrace& Object) {
if (!Object.GetUnderlyingPtr()) {
lua_pushnil(L);
return;
}
FLuaObject* LuaObject = static_cast<FLuaObject*>(lua_newuserdata(L, sizeof(FLuaObject)));
new (LuaObject) FLuaObject(Object, UFINLuaProcessor::luaGetProcessor(L)->GetKernel());
new(LuaObject) FLuaObject(Object, UFINLuaProcessor::luaGetProcessor(L)->GetKernel());
luaL_setmetatable(L, FIN_LUA_OBJECT_METATABLE_NAME);
}

Expand All @@ -174,24 +183,24 @@ namespace FINLua {
}
return LuaObject->Object;
}

FFINNetworkTrace luaFIN_checkObject(lua_State* L, int Index, UFINClass* ParentType) {
TOptional<FFINNetworkTrace> Object = luaFIN_toObject(L, Index, ParentType);
if (!Object.IsSet()) luaFIN_typeError(L, Index, FFINReflection::ObjectReferenceText(ParentType));
return *Object;
}

void setupObjectSystem(lua_State* L) {
PersistSetup("ObjectSystem", -2);

// Register & Persist Class-Metatable
luaL_newmetatable(L, FIN_LUA_OBJECT_METATABLE_NAME); // ..., ObjectMetatable
luaL_newmetatable(L, FIN_LUA_OBJECT_METATABLE_NAME); // ..., ObjectMetatable
luaL_setfuncs(L, luaObjectMetatable, 0);
lua_pushstring(L, FIN_LUA_OBJECT_METATABLE_NAME); // ..., ObjectMetatable, string
lua_setfield(L, -2, "__metatable"); // ..., ObjectMetatable
lua_pushstring(L, FIN_LUA_OBJECT_METATABLE_NAME); // ..., ObjectMetatable, string
lua_setfield(L, -2, "__metatable"); // ..., ObjectMetatable
PersistTable(FIN_LUA_OBJECT_METATABLE_NAME, -1);
lua_pop(L, 1); // ...
lua_pushcfunction(L, luaObjectUnpersist); // ..., ObjectUnpersist
PersistValue("ObjectUnpersist"); // ...
lua_pop(L, 1); // ...
lua_pushcfunction(L, luaObjectUnpersist); // ..., ObjectUnpersist
PersistValue("ObjectUnpersist"); // ...
}
}

0 comments on commit 9c2b2ec

Please sign in to comment.