Finished implementing the ReadLuaValues K2Node
This commit is contained in:
@@ -276,7 +276,7 @@ bool UlxLuaCallLibrary::LuaCallProbe(UObject *context, AActor *place, UlxLuaValu
|
||||
}
|
||||
ElxSuccessOrWrongType Status;
|
||||
FString ErrorMessage;
|
||||
ReturnArray->ReadString(Status, ErrorMessage, false);
|
||||
ReturnArray->ReadString(Status, ErrorMessage);
|
||||
if (Status != ElxSuccessOrWrongType::Success)
|
||||
{
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("lua probe should always return an error message (possibly empty) as the first parameter"));
|
||||
@@ -289,6 +289,7 @@ bool UlxLuaCallLibrary::LuaCallProbe(UObject *context, AActor *place, UlxLuaValu
|
||||
ReturnArray = nullptr;
|
||||
return false;
|
||||
}
|
||||
ReturnArray->DiscardBeforeCursor();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -383,7 +384,6 @@ bool UlxLuaValues::Initialize(std::string_view data)
|
||||
while (!Decoder.empty())
|
||||
{
|
||||
LuaValueType Tag = Decoder.read_lua_value_type();
|
||||
|
||||
int64 Pos = Decoder.total_reads();
|
||||
ElxLuaValueType Type;
|
||||
switch (Tag)
|
||||
@@ -411,7 +411,7 @@ FString UlxLuaValues::DebugString() const
|
||||
Output << TEXT("{ ");
|
||||
for (int i = 0; i < Types.Num(); i++)
|
||||
{
|
||||
if (i > 0) Output << TEXT(", ");
|
||||
if (i > 0) Output << TEXT(" ");
|
||||
|
||||
if (i == Cursor) Output << TEXT("^ ");
|
||||
|
||||
@@ -442,31 +442,15 @@ FString UlxLuaValues::DebugString() const
|
||||
return Output.ToString();
|
||||
}
|
||||
|
||||
ElxSuccessOrWrongType UlxLuaValues::CheckType(bool LogErrorOnWrongType, ElxLuaValueType Type, ElxLuaValueType Desired)
|
||||
ElxSuccessOrWrongType UlxLuaValues::CheckType(ElxLuaValueType Type, ElxLuaValueType Desired)
|
||||
{
|
||||
if (Type != Desired)
|
||||
{
|
||||
if (LogErrorOnWrongType)
|
||||
{
|
||||
FString TypeName = StaticEnum<ElxLuaValueType>()->GetDisplayNameTextByValue(int64(Type)).ToString();
|
||||
FString DesiredName = StaticEnum<ElxLuaValueType>()->GetDisplayNameTextByValue(int64(Desired)).ToString();
|
||||
UE_LOG(LogBlueprint, Error, TEXT("Expected a value of type %s, but found %s instead."), *DesiredName, *TypeName);
|
||||
}
|
||||
return ElxSuccessOrWrongType::WrongType;
|
||||
}
|
||||
return ElxSuccessOrWrongType::Success;
|
||||
}
|
||||
|
||||
void UlxLuaValues::DiscardBeforeCursor()
|
||||
{
|
||||
if (Cursor <= 0) return;
|
||||
int Discard = Cursor;
|
||||
if (Discard > Types.Num()) Discard = Types.Num();
|
||||
Types.RemoveAt(0, Discard);
|
||||
Data.RemoveAt(0, Discard);
|
||||
Cursor -= Discard;
|
||||
}
|
||||
|
||||
ElxLuaValueType UlxLuaValues::NextType() const
|
||||
{
|
||||
if (Cursor < 0) return ElxLuaValueType::End;
|
||||
@@ -474,78 +458,90 @@ ElxLuaValueType UlxLuaValues::NextType() const
|
||||
return Types[Cursor];
|
||||
}
|
||||
|
||||
void UlxLuaValues::ReadString(ElxSuccessOrWrongType &Status, FString &Result, bool LogErrorOnMismatch)
|
||||
void UlxLuaValues::DiscardBeforeCursor()
|
||||
{
|
||||
Status = CheckType(LogErrorOnMismatch, NextType(), ElxLuaValueType::String);
|
||||
if (Cursor > 0)
|
||||
{
|
||||
Types.RemoveAt(0, Cursor);
|
||||
Data.RemoveAt(0, Cursor);
|
||||
SavedCursor = FMath::Max(0, SavedCursor - Cursor);
|
||||
Cursor = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void UlxLuaValues::ReadString(ElxSuccessOrWrongType &Status, FString &Result)
|
||||
{
|
||||
Status = CheckType(NextType(), ElxLuaValueType::String);
|
||||
if (Status == ElxSuccessOrWrongType::WrongType)
|
||||
{
|
||||
Result.Empty(); return;
|
||||
Cursor = SavedCursor; Result.Empty(); return;
|
||||
}
|
||||
Result = FlxStreamBuffer(Data[Cursor++]).read_fstring();
|
||||
}
|
||||
|
||||
void UlxLuaValues::ReadName(ElxSuccessOrWrongType &Status, FName &Result, bool LogErrorOnMismatch)
|
||||
void UlxLuaValues::ReadName(ElxSuccessOrWrongType &Status, FName &Result)
|
||||
{
|
||||
Status = CheckType(LogErrorOnMismatch, NextType(), ElxLuaValueType::Name);
|
||||
Status = CheckType(NextType(), ElxLuaValueType::Name);
|
||||
if (Status == ElxSuccessOrWrongType::WrongType)
|
||||
{
|
||||
Result = FName(); return;
|
||||
Cursor = SavedCursor; Result = FName(); return;
|
||||
}
|
||||
Result = FlxStreamBuffer(Data[Cursor++]).read_fname();
|
||||
}
|
||||
|
||||
void UlxLuaValues::ReadFloat(ElxSuccessOrWrongType &Status, double &Result, bool LogErrorOnMismatch)
|
||||
void UlxLuaValues::ReadFloat(ElxSuccessOrWrongType &Status, double &Result)
|
||||
{
|
||||
Status = CheckType(LogErrorOnMismatch, NextType(), ElxLuaValueType::Float);
|
||||
Status = CheckType(NextType(), ElxLuaValueType::Float);
|
||||
if (Status == ElxSuccessOrWrongType::WrongType)
|
||||
{
|
||||
Result = 0.0; return;
|
||||
Cursor = SavedCursor; Result = 0.0; return;
|
||||
}
|
||||
Result = FlxStreamBuffer(Data[Cursor++]).read_double();
|
||||
}
|
||||
|
||||
void UlxLuaValues::ReadInt(ElxSuccessOrWrongType &Status, int &Result, bool LogErrorOnMismatch)
|
||||
void UlxLuaValues::ReadInt(ElxSuccessOrWrongType &Status, int &Result)
|
||||
{
|
||||
Status = CheckType(LogErrorOnMismatch, NextType(), ElxLuaValueType::Float);
|
||||
Status = CheckType(NextType(), ElxLuaValueType::Float);
|
||||
if (Status == ElxSuccessOrWrongType::WrongType)
|
||||
{
|
||||
Result = 0.0; return;
|
||||
Cursor = SavedCursor; Result = 0; return;
|
||||
}
|
||||
double dvalue = FlxStreamBuffer(Data[Cursor++]).read_double();
|
||||
Result = int(dvalue);
|
||||
if (double(Result) != dvalue)
|
||||
{
|
||||
Result = 0; Status = ElxSuccessOrWrongType::WrongType; return;
|
||||
Status = ElxSuccessOrWrongType::WrongType;
|
||||
Cursor = SavedCursor; Result = 0; return;
|
||||
}
|
||||
}
|
||||
|
||||
void UlxLuaValues::ReadVector(ElxSuccessOrWrongType &Status, FVector &Result, bool LogErrorOnMismatch)
|
||||
void UlxLuaValues::ReadVector(ElxSuccessOrWrongType &Status, FVector &Result)
|
||||
{
|
||||
Status = CheckType(LogErrorOnMismatch, NextType(), ElxLuaValueType::Vector);
|
||||
Status = CheckType(NextType(), ElxLuaValueType::Vector);
|
||||
if (Status == ElxSuccessOrWrongType::WrongType)
|
||||
{
|
||||
Result = FVector(); return;
|
||||
Cursor = SavedCursor; Result = FVector(); return;
|
||||
}
|
||||
Result = FlxStreamBuffer(Data[Cursor++]).read_fvector();
|
||||
}
|
||||
|
||||
void UlxLuaValues::ReadVector2D(ElxSuccessOrWrongType &Status, FVector2D &Result, bool LogErrorOnMismatch)
|
||||
void UlxLuaValues::ReadVector2D(ElxSuccessOrWrongType &Status, FVector2D &Result)
|
||||
{
|
||||
Status = CheckType(LogErrorOnMismatch, NextType(), ElxLuaValueType::Vector);
|
||||
Status = CheckType(NextType(), ElxLuaValueType::Vector);
|
||||
if (Status == ElxSuccessOrWrongType::WrongType)
|
||||
{
|
||||
Result = FVector2D(); return;
|
||||
Cursor = SavedCursor; Result = FVector2D(); return;
|
||||
}
|
||||
FVector VValue = FlxStreamBuffer(Data[Cursor++]).read_fvector();
|
||||
Result = FVector2D(VValue.X, VValue.Y);
|
||||
}
|
||||
|
||||
void UlxLuaValues::ReadBoolean(ElxSuccessOrWrongType &Status, bool &Result, bool LogErrorOnMismatch)
|
||||
void UlxLuaValues::ReadBoolean(ElxSuccessOrWrongType &Status, bool &Result)
|
||||
{
|
||||
Status = CheckType(LogErrorOnMismatch, NextType(), ElxLuaValueType::Boolean);
|
||||
Status = CheckType(NextType(), ElxLuaValueType::Boolean);
|
||||
if (Status == ElxSuccessOrWrongType::WrongType)
|
||||
{
|
||||
Result = false; return;
|
||||
Cursor = SavedCursor; Result = false; return;
|
||||
}
|
||||
Result = FlxStreamBuffer(Data[Cursor++]).read_bool();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user