Add support for LuaToken to the LuaCall unreal pipeline
This commit is contained in:
@@ -30,6 +30,13 @@ void UlxLuaCallLibrary::LuaCallAddStringParameter(UObject *context, const FStrin
|
||||
sb.write_string(pstring);
|
||||
}
|
||||
|
||||
void UlxLuaCallLibrary::LuaCallAddNameParameter(UObject *context, const FName &pname) {
|
||||
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
CheckNotEmpty(sb);
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::STRING);
|
||||
sb.write_fname(pname);
|
||||
}
|
||||
|
||||
void UlxLuaCallLibrary::LuaCallAddFloatParameter(UObject *context, double pfloat) {
|
||||
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
|
||||
@@ -47,7 +54,7 @@ void UlxLuaCallLibrary::LuaCallAddVectorParameter(UObject *context, const FVecto
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::VECTOR);
|
||||
sb.write_fvector(pvector);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UlxLuaCallLibrary::LuaCallAddBooleanParameter(UObject *context, bool pbool) {
|
||||
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
|
||||
@@ -98,6 +105,7 @@ ELpxSimpleDynamicTag UlxLuaCallLibrary::LuaCallNextResultType(UObject *context)
|
||||
sb.unread_to(total_reads);
|
||||
switch (tag) {
|
||||
case SimpleDynamicTag::STRING: return ELpxSimpleDynamicTag::String;
|
||||
case SimpleDynamicTag::TOKEN: return ELpxSimpleDynamicTag::Name;
|
||||
case SimpleDynamicTag::NUMBER: return ELpxSimpleDynamicTag::Float;
|
||||
case SimpleDynamicTag::VECTOR: return ELpxSimpleDynamicTag::Vector;
|
||||
case SimpleDynamicTag::BOOLEAN: return ELpxSimpleDynamicTag::Boolean;
|
||||
@@ -110,8 +118,15 @@ FString UlxLuaCallLibrary::LuaCallGetStringResult(UObject *context) {
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::STRING) FatalBlueprintError(TEXT("expected lua to return a string"));
|
||||
std::string_view s = sb.read_string_view();
|
||||
return FString(s.size(), (const UTF8CHAR *)s.data());
|
||||
return sb.read_fstring();
|
||||
}
|
||||
|
||||
FName UlxLuaCallLibrary::LuaCallGetNameResult(UObject *context) {
|
||||
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::TOKEN) FatalBlueprintError(TEXT("expected lua to return a name"));
|
||||
return sb.read_fname();
|
||||
}
|
||||
|
||||
double UlxLuaCallLibrary::LuaCallGetFloatResult(UObject *context) {
|
||||
|
||||
@@ -7,6 +7,7 @@ UENUM(BlueprintType)
|
||||
enum class ELpxSimpleDynamicTag : uint8 {
|
||||
None,
|
||||
String,
|
||||
Name,
|
||||
Float,
|
||||
Boolean,
|
||||
Vector
|
||||
@@ -31,7 +32,10 @@ public:
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
||||
static void LuaCallAddStringParameter(UObject *context, const FString &pstring);
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
||||
static void LuaCallAddNameParameter(UObject *context, const FName &pname);
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
||||
static void LuaCallAddFloatParameter(UObject *context, double pfloat);
|
||||
|
||||
@@ -56,6 +60,9 @@ public:
|
||||
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
||||
static FString LuaCallGetStringResult(UObject *context);
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
||||
static FName LuaCallGetNameResult(UObject *context);
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
||||
static double LuaCallGetFloatResult(UObject *context);
|
||||
|
||||
|
||||
@@ -37,6 +37,11 @@ public:
|
||||
write_string(std::string_view(utf8str.Get(), utf8str.Length()));
|
||||
}
|
||||
|
||||
void write_fname(const FName &name) {
|
||||
FTCHARToUTF8 utf8str(name.ToString());
|
||||
write_string(std::string_view(utf8str.Get(), utf8str.Length()));
|
||||
}
|
||||
|
||||
void write_string(const char *s) {
|
||||
write_string(std::string_view(s));
|
||||
}
|
||||
@@ -53,5 +58,15 @@ public:
|
||||
double z = read_double();
|
||||
return FVector(x, y, z);
|
||||
}
|
||||
|
||||
FString read_fstring() {
|
||||
std::string_view s = read_string_view();
|
||||
return FString(s.size(), (const UTF8CHAR *)s.data());
|
||||
}
|
||||
|
||||
FName read_fname() {
|
||||
std::string_view s = read_string_view();
|
||||
return FName(s.size(), (const UTF8CHAR *)s.data(), FNAME_Add);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user