Skip to content

Commit

Permalink
feat: Add Static Prop to Reflection & Add static funcs/props to Lua i…
Browse files Browse the repository at this point in the history
…mplementation
  • Loading branch information
Panakotta00 committed Jul 26, 2024
1 parent 97e4b72 commit 7cfaedd
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ void UFINStaticReflectionSource::FillData(FFINReflection* Ref, UFINClass* ToFill
case 1:
FINProp->PropertyFlags = FINProp->PropertyFlags | FIN_Prop_ClassProp;
break;
case 2:
FINProp->PropertyFlags = FINProp->PropertyFlags | FIN_Prop_StaticProp;
break;
default:
break;
}
Expand Down Expand Up @@ -361,6 +364,9 @@ void UFINStaticReflectionSource::FillData(FFINReflection* Ref, UFINStruct* ToFil
case 1:
FINProp->PropertyFlags = FINProp->PropertyFlags | FIN_Prop_ClassProp;
break;
case 2:
FINProp->PropertyFlags = FINProp->PropertyFlags | FIN_Prop_StaticProp;
break;
default:
break;
}
Expand Down Expand Up @@ -420,7 +426,8 @@ void UFINStaticReflectionSource::FillData(FFINReflection* Ref, UFINStruct* ToFil
T* self = GetFromCtx(Ctx);
#define BeginClassFunc(InternalName, DisplayName, Description, VA, ...) BeginFuncRT(Class, InternalName, DisplayName, Description, VA, 1, GET_MACRO(0, ##__VA_ARGS__, 1) ) \
TSubclassOf<T> self = Cast<UClass>(Ctx.GetObject());
#define BeginStaticFunc(InternalName, DisplayName, Description, VA, ...) BeginFuncRT(Static, InternalName, DisplayName, Description, VA, 2, GET_MACRO(0, ##__VA_ARGS__, 1) )
#define BeginStaticFunc(InternalName, DisplayName, Description, VA, ...) BeginFuncRT(Static, InternalName, DisplayName, Description, VA, 2, GET_MACRO(0, ##__VA_ARGS__, 1) ) \
void* self = Ctx.GetGeneric();
#define Body() \
if (self && _bGotReg) {
#define EndFunc() \
Expand All @@ -444,6 +451,7 @@ void UFINStaticReflectionSource::FillData(FFINReflection* Ref, UFINStruct* ToFil
T* self = GetFromCtx(Ctx);
#define BeginClassProp(Type, InternalName, DisplayName, Description, ...) BeginPropRT(Class, Type, InternalName, DisplayName, Description, 1, GET_MACRO(0, ##__VA_ARGS__, 1) ) \
TSubclassOf<T> self = Cast<UClass>(Ctx.GetObject());
#define BeginStaticProp(Type, InternalName, DisplayName, Description, ...) BeginPropRT(Class, Type, InternalName, DisplayName, Description, 2, GET_MACRO(0, ##__VA_ARGS__, 1) )
#define Return \
return (FINAny)
#define PropSet() \
Expand Down
29 changes: 15 additions & 14 deletions Source/FicsItNetworks/Public/Reflection/FINProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
UENUM(BlueprintType)
enum EFINRepPropertyFlags {
FIN_Prop_None = 0,
FIN_Prop_Attrib = 0b0000000001,
FIN_Prop_ReadOnly = 0b0000000010,
FIN_Prop_Param = 0b0000000100,
FIN_Prop_OutParam = 0b0000001000,
FIN_Prop_RetVal = 0b0000010000,
FIN_Prop_Runtime = 0b0011100000,
FIN_Prop_RT_Sync = 0b0000100000,
FIN_Prop_RT_Parallel = 0b0001000000,
FIN_Prop_RT_Async = 0b0010000000,
FIN_Prop_Sync = 0b0000100000,
FIN_Prop_Parallel = 0b0001100000,
FIN_Prop_Async = 0b0011100000,
FIN_Prop_ClassProp = 0b0100000000,
FIN_Prop_StaticSource = 0b1000000000,
FIN_Prop_Attrib = 0b00000000001,
FIN_Prop_ReadOnly = 0b00000000010,
FIN_Prop_Param = 0b00000000100,
FIN_Prop_OutParam = 0b00000001000,
FIN_Prop_RetVal = 0b00000010000,
FIN_Prop_Runtime = 0b00011100000,
FIN_Prop_RT_Sync = 0b00000100000,
FIN_Prop_RT_Parallel = 0b00001000000,
FIN_Prop_RT_Async = 0b00010000000,
FIN_Prop_Sync = 0b00000100000,
FIN_Prop_Parallel = 0b00001100000,
FIN_Prop_Async = 0b00011100000,
FIN_Prop_ClassProp = 0b00100000000,
FIN_Prop_StaticSource = 0b01000000000,
FIN_Prop_StaticProp = 0b10000000000,
};

ENUM_CLASS_FLAGS(EFINRepPropertyFlags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace FINGenJsonDoc {
if (Flags & FIN_Prop_RT_Parallel) FlagArray.Add(MakeShared<FJsonValueString>(TEXT("RT_Parallel")));
if (Flags & FIN_Prop_RT_Async) FlagArray.Add(MakeShared<FJsonValueString>(TEXT("RT_Async")));
if (Flags & FIN_Prop_ClassProp) FlagArray.Add(MakeShared<FJsonValueString>(TEXT("ClassProp")));
if (Flags & FIN_Prop_StaticProp) FlagArray.Add(MakeShared<FJsonValueString>(TEXT("StaticProp")));
Obj->SetArrayField(TEXT("flags"), FlagArray);
}

Expand Down
13 changes: 11 additions & 2 deletions Source/FicsItNetworksDocumentation/Private/CMD/FINCMDGenLuaDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ namespace FINGenLuaDoc {
}

void WriteProperty(FStringBuilderBase& Documentation, FFINReflection& Ref, UFINProperty* Prop) {
Documentation.Appendf(TEXT("---@field public %s %s %s\n"), *Prop->GetInternalName(), *GetType(Ref, Prop), *GetInlineDescription(Prop->GetDescription().ToString()));
FString Identifier = Prop->GetInternalName();
if (Prop->GetPropertyFlags() & (FIN_Prop_ClassProp | FIN_Prop_StaticProp)) {
Identifier += TEXT("-Class");
}
Documentation.Appendf(TEXT("---@field public %s %s %s\n"), *Identifier, *GetType(Ref, Prop), *GetInlineDescription(Prop->GetDescription().ToString()));
}

void WriteFunction(FStringBuilderBase& Str, FFINReflection& Ref, const FString& Parent, const FString& Type, UFINFunction* Func) {
Expand Down Expand Up @@ -211,7 +215,12 @@ namespace FINGenLuaDoc {

Str.Appendf(TEXT("---@type (fun(%s)%s)|ReflectionFunction\n"), *FString::Join(typedParameterList, TEXT(",")), *functionTypedReturn);

Str.Appendf(TEXT("function %s:%s(%s) end\n"), *Parent, *Func->GetInternalName(), *FString::Join(paramList, TEXT(", ")));
FString Identifier = Func->GetInternalName();
if (Func->GetFunctionFlags() & (FIN_Func_ClassFunc | FIN_Func_StaticFunc)) {
Identifier += TEXT("-Class");
}

Str.Appendf(TEXT("function %s:%s(%s) end\n"), *Parent, *Identifier, *FString::Join(paramList, TEXT(", ")));

if (bFuture) {
WriteFuture(Str, Type, Func->GetInternalName(), futureParameterList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace FINLua {
FString MemberName = luaFIN_toFString(L, nameIndex);

FFINExecutionContext Context(LuaClass->UClass);
return luaFIN_pushFunctionOrGetProperty(L, thisIndex, LuaClass->FINClass, MemberName, FIN_Func_ClassFunc, FIN_Prop_ClassProp, Context, true);
return luaFIN_pushFunctionOrGetProperty(L, thisIndex, LuaClass->FINClass, MemberName, FIN_Func_ClassFunc | FIN_Func_StaticFunc, FIN_Prop_ClassProp | FIN_Prop_StaticProp, Context, true);
}

LuaModuleTableFunction(R"(/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ namespace FINLua {
lua_remove(L, 1);

FFINExecutionContext Context;
if (UFINClass* Class = Cast<UFINClass>(Type)) {
if (Function->GetFunctionFlags() & FIN_Func_StaticFunc) {
Context = FFINExecutionContext(Function->GetOuter());
} else if (UFINClass* Class = Cast<UFINClass>(Type)) {
if (Function->GetFunctionFlags() & FIN_Func_ClassFunc) {
FLuaClass* LuaClass = luaFIN_checkLuaClass(L, 1);
if (!LuaClass->FINClass->IsChildOf(Class)) luaL_argerror(L, 1, "Expected Class");
Expand Down
16 changes: 16 additions & 0 deletions Source/FicsItNetworksLua/Private/FINLua/Reflection/LuaStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,22 @@ namespace FINLua {
return 1;
}

LuaModuleTableFunction(R"(/**
* @LuaFunction __index
* @DisplayName Index
*/)", __index) {
const int thisIndex = 1;
const int nameIndex = 2;

UFINStruct* Struct = luaFIN_toStructType(L, thisIndex);
if (!Struct) return 0;

FString MemberName = luaFIN_toFString(L, nameIndex);

FFINExecutionContext Context(Struct);
return luaFIN_pushFunctionOrGetProperty(L, thisIndex, Struct, MemberName, FIN_Func_StaticFunc, FIN_Prop_StaticProp, Context, true);
}

int luaStructTypeUnpersist(lua_State* L) {
FString StructName = luaFIN_checkFString(L, lua_upvalueindex(1));
UFINStruct* Struct = FFINReflection::Get()->FindStruct(StructName);
Expand Down

0 comments on commit 7cfaedd

Please sign in to comment.