Overhaul the handling of return values in LuaProbe
This commit is contained in:
@@ -169,16 +169,14 @@ void FlxParsedProto::Parse(const FString &str) {
|
||||
|
||||
UFunction *UlxLuaCallLibrary::GetArgumentPacker(const FString &Type)
|
||||
{
|
||||
FString LType = Type.ToLower();
|
||||
FName PackerName(FString::Printf(TEXT("LuaCallArgument_%s"), *LType));
|
||||
FName PackerName(FString::Printf(TEXT("LuaCallArgument_%s"), *Type));
|
||||
return UlxLuaCallLibrary::StaticClass()->FindFunctionByName(PackerName);
|
||||
}
|
||||
|
||||
UFunction *UlxLuaCallLibrary::GetReturnValueUnpacker(const FString &Type)
|
||||
{
|
||||
FString LType = Type.ToLower();
|
||||
FName PackerName(FString::Printf(TEXT("LuaCallReturnValue_%s"), *LType));
|
||||
return UlxLuaCallLibrary::StaticClass()->FindFunctionByName(PackerName);
|
||||
FName PackerName(FString::Printf(TEXT("Read%s"), *Type));
|
||||
return UlxLuaValues::StaticClass()->FindFunctionByName(PackerName);
|
||||
}
|
||||
|
||||
FString UlxLuaCallLibrary::AllFunctionsWithPrefix(const TCHAR *Prefix)
|
||||
@@ -223,41 +221,36 @@ void UlxLuaCallLibrary::LuaCallInvoke(UObject *context, AActor *place)
|
||||
}
|
||||
|
||||
|
||||
bool UlxLuaCallLibrary::LuaCallProbe(UObject *context, AActor *place)
|
||||
bool UlxLuaCallLibrary::LuaCallProbe(UObject *context, AActor *place, UlxLuaValues *&ReturnArray)
|
||||
{
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
if (NotInitialized(sb)) return false;
|
||||
mode->LuaCallEnd(InvocationKind::LUA_PROBE, place);
|
||||
FlxStreamBuffer &result = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = result.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::STRING)
|
||||
{
|
||||
ReturnArray = mode->LuaCallEnd(InvocationKind::LUA_PROBE, place);
|
||||
if ((ReturnArray == nullptr) || (ReturnArray->Length() < 1))
|
||||
{
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("corruption in lua_probe"));
|
||||
ReturnArray = nullptr;
|
||||
return false;
|
||||
}
|
||||
FString ErrorMessage = result.read_fstring();
|
||||
ElxSuccessOrError Status;
|
||||
FString ErrorMessage;
|
||||
ReturnArray->ReadString(Status, ErrorMessage);
|
||||
if (Status != ElxSuccessOrError::Success)
|
||||
{
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("corruption in lua_probe"));
|
||||
ReturnArray = nullptr;
|
||||
return false;
|
||||
}
|
||||
if (!ErrorMessage.IsEmpty())
|
||||
{
|
||||
UE_LOG(LogLuprex, Error, TEXT("%s"), *ErrorMessage);
|
||||
ReturnArray = nullptr;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
UlxLuaValues *UlxLuaCallLibrary::LuaCallGetRest(UObject *context)
|
||||
{
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
UlxLuaValues *Values = NewObject<UlxLuaValues>(context);
|
||||
if (!Values->Initialize(sb.view()))
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("Lua call returned corrupt data"));
|
||||
return nullptr;
|
||||
}
|
||||
return Values;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Argument Packing functions
|
||||
@@ -330,98 +323,6 @@ void UlxLuaCallLibrary::LuaCallArgument_boolean(UObject *context, bool pbool) {
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Return Value Unpacking functions
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
FString UlxLuaCallLibrary::LuaCallReturnValue_string(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::STRING)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a string"));
|
||||
return TEXT("");
|
||||
}
|
||||
return sb.read_fstring();
|
||||
}
|
||||
|
||||
FName UlxLuaCallLibrary::LuaCallReturnValue_name(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::TOKEN)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a name"));
|
||||
return FName();
|
||||
}
|
||||
return sb.read_fname();
|
||||
}
|
||||
|
||||
double UlxLuaCallLibrary::LuaCallReturnValue_float(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::NUMBER)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a float"));
|
||||
return 0.0;
|
||||
}
|
||||
return sb.read_double();
|
||||
}
|
||||
|
||||
int UlxLuaCallLibrary::LuaCallReturnValue_int(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::NUMBER)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a number"));
|
||||
return 0;
|
||||
}
|
||||
return int(sb.read_double());
|
||||
}
|
||||
|
||||
FVector UlxLuaCallLibrary::LuaCallReturnValue_vector(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::VECTOR)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a vector"));
|
||||
return FVector();
|
||||
}
|
||||
return sb.read_fvector();
|
||||
}
|
||||
|
||||
FVector2D UlxLuaCallLibrary::LuaCallReturnValue_vector2d(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::VECTOR)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a vector"));
|
||||
return FVector2D();
|
||||
}
|
||||
FVector v = sb.read_fvector();
|
||||
return FVector2D(v.X, v.Y);
|
||||
}
|
||||
|
||||
bool UlxLuaCallLibrary::LuaCallReturnValue_boolean(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::BOOLEAN)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a boolean"));
|
||||
return false;
|
||||
}
|
||||
return sb.read_bool();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Returning the rest of the lua return values as an array.
|
||||
@@ -478,6 +379,8 @@ FString UlxLuaValues::DebugString() const
|
||||
{
|
||||
if (i > 0) Output << TEXT(", ");
|
||||
|
||||
if (i == Cursor) Output << TEXT("^ ");
|
||||
|
||||
ElxLuaValueType Type = Types[i];
|
||||
FlxStreamBuffer Decoder(Data[i]);
|
||||
switch (Type)
|
||||
@@ -517,6 +420,16 @@ ElxSuccessOrError UlxLuaValues::CheckType(ElxLuaValueType Type, ElxLuaValueType
|
||||
return ElxSuccessOrError::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;
|
||||
|
||||
Reference in New Issue
Block a user