Implemented ULxLuaValues (not tested yet)
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
#include "CoreMinimal.h"
|
||||
#include "lpx-basebuffer.hpp"
|
||||
|
||||
|
||||
using FlxSimpleDynamic = SimpleDynamic<std::string>;
|
||||
#include "StringDecoder.generated.h"
|
||||
|
||||
class FlxStreamBufferCore {
|
||||
private:
|
||||
@@ -70,3 +69,137 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// These are the types that can actually be packed into
|
||||
// a serialized buffer.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
UENUM(BlueprintType)
|
||||
enum class ELxLuaValueType : uint8 {
|
||||
None,
|
||||
String,
|
||||
Name,
|
||||
Float,
|
||||
Boolean,
|
||||
Vector
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// This class stores an array of values that were returned by Lua.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
UCLASS(MinimalAPI)
|
||||
class UlxLuaValues : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
private:
|
||||
// The raw serialized data returned by Lua.
|
||||
//
|
||||
std::string Serialized;
|
||||
|
||||
// For each chunk, the type of the chunk.
|
||||
//
|
||||
TArray<ELxLuaValueType> Types;
|
||||
|
||||
// For each chunk, a pointer to the serialized data.
|
||||
//
|
||||
TArray<std::string_view> Data;
|
||||
|
||||
// The current cursor.
|
||||
//
|
||||
int Cursor;
|
||||
|
||||
private:
|
||||
// Clear everything.
|
||||
//
|
||||
void Empty();
|
||||
|
||||
// Copies the data, and then preprocesses it to make sure
|
||||
// it's all valid. If it's not valid, returns false.
|
||||
//
|
||||
bool Initialize(std::string_view data);
|
||||
|
||||
// Compare two types. If they aren't equal, log an error and return false.
|
||||
//
|
||||
static bool CheckType(ELxLuaValueType Type, ELxLuaValueType Desired);
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
int Length() const { return Types.Num(); }
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
int GetCursor() const { return Cursor; }
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Luprex|Lua Value Array")
|
||||
void SetCursor(int n) { Cursor = n; }
|
||||
|
||||
private:
|
||||
//
|
||||
// Functions that get values from the array, random access.
|
||||
//
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
ELxLuaValueType GetType(int n) const;
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
bool IsType(int n, ELxLuaValueType Type) const { return GetType(n) == Type; }
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
FString GetString(int n) const;
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
FName GetName(int n) const;
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
double GetFloat(int n) const;
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
int GetInt(int n) const;
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
FVector GetVector(int n) const;
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
FVector2D GetVector2D(int n) const;
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
bool GetBoolean(int n) const;
|
||||
|
||||
//
|
||||
// Functions that get values from the array using the cursor.
|
||||
//
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
ELxLuaValueType NextType() const { return GetType(Cursor); }
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Luprex|Lua Value Array")
|
||||
bool IsNextType(ELxLuaValueType Type) const { return IsType(Cursor, Type); }
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Luprex|Lua Value Array")
|
||||
FString ReadString() { return GetString(Cursor++); }
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Luprex|Lua Value Array")
|
||||
FName ReadName() { return GetName(Cursor++); }
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Luprex|Lua Value Array")
|
||||
double ReadFloat() { return GetFloat(Cursor++); }
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Luprex|Lua Value Array")
|
||||
int ReadInt() { return GetInt(Cursor++); }
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Luprex|Lua Value Array")
|
||||
FVector ReadVector() { return GetVector(Cursor++); }
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Luprex|Lua Value Array")
|
||||
FVector2D ReadVector2D() { return GetVector2D(Cursor++); }
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Luprex|Lua Value Array")
|
||||
bool ReadBoolean() { return GetBoolean(Cursor++); }
|
||||
};
|
||||
Reference in New Issue
Block a user