Implement Static Function Pointers

This commit is contained in:
Ricardo Luís Vaz Silva 2023-02-10 09:44:32 -03:00 committed by Christoph Oelckers
commit e3704605d8
23 changed files with 876 additions and 51 deletions

View file

@ -1656,6 +1656,84 @@ FSerializer &Serialize(FSerializer &arc, const char *key, NumericValue &value, N
return arc;
}
//==========================================================================
//
// PFunctionPointer
//
//==========================================================================
void SerializeFunctionPointer(FSerializer &arc, const char *key, FunctionPointerValue *&p)
{
if (arc.isWriting())
{
if(p)
{
arc.BeginObject(key);
arc("Class",p->ClassName);
arc("Function",p->FunctionName);
arc.EndObject();
}
else
{
arc.WriteKey(key);
arc.w->Null();
}
}
else
{
assert(p);
auto v = arc.r->FindKey(key);
if(!v || v->IsNull())
{
p = nullptr;
}
else if(v->IsObject())
{
arc.r->mObjects.Push(FJSONObject(v)); // BeginObject
const char * cstr;
arc.StringPtr("Class", cstr);
if(!cstr)
{
arc.StringPtr("Function", cstr);
if(!cstr)
{
Printf(TEXTCOLOR_RED "Function Pointer missing Class and Function Fields in Object\n");
}
else
{
Printf(TEXTCOLOR_RED "Function Pointer missing Class Field in Object\n");
}
arc.mErrors++;
arc.EndObject();
p = nullptr;
return;
}
p->ClassName = FString(cstr);
arc.StringPtr("Function", cstr);
if(!cstr)
{
Printf(TEXTCOLOR_RED "Function Pointer missing Function Field in Object\n");
arc.mErrors++;
arc.EndObject();
p = nullptr;
return;
}
p->FunctionName = FString(cstr);
arc.EndObject();
}
else
{
Printf(TEXTCOLOR_RED "Function Pointer is not an Object\n");
arc.mErrors++;
p = nullptr;
}
}
}
#include "renderstyle.h"
FSerializer& Serialize(FSerializer& arc, const char* key, FRenderStyle& style, FRenderStyle* def)
{