2024-08-31 16:42:07 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
2025-02-26 14:47:53 -05:00
|
|
|
#include "EdGraph/EdGraphPin.h"
|
2025-03-28 23:31:44 -04:00
|
|
|
|
2024-08-31 16:42:07 -04:00
|
|
|
#include "LuaCall.generated.h"
|
|
|
|
|
|
2025-03-28 23:31:44 -04:00
|
|
|
class UlxLuaValues;
|
2025-02-26 14:47:53 -05:00
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// This is a little parser that parses Lua function 'prototypes'.
|
|
|
|
|
// The prototypes look like this:
|
|
|
|
|
//
|
|
|
|
|
// class.name(int arg1, int arg2) : int ret1, int ret2
|
|
|
|
|
//
|
|
|
|
|
// The return values can be omitted if the function has no return
|
|
|
|
|
// values. Optionally, there can be one last return value which
|
|
|
|
|
// is just an ellipsis. The class name can be asterisk.
|
|
|
|
|
//
|
|
|
|
|
// For more information about the meaning of all this, see the docs
|
|
|
|
|
// for the 'Call Lua' blueprint node.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class FlxParsedProto
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
struct Pin
|
|
|
|
|
{
|
|
|
|
|
FString Type;
|
|
|
|
|
FString Name;
|
|
|
|
|
Pin(const FString &T, const FString &N) : Type(T), Name(N) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FString ErrorMessage;
|
|
|
|
|
TArray<FString> Tokens;
|
|
|
|
|
int NextToken;
|
|
|
|
|
FString ClassName;
|
|
|
|
|
FString FunctionName;
|
|
|
|
|
TArray<Pin> Arguments;
|
|
|
|
|
TArray<Pin> ReturnValues;
|
|
|
|
|
bool ExtraReturnValues;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Check the next token to see if it's exactly equal to text.
|
|
|
|
|
//
|
|
|
|
|
bool IsLiteral(const TCHAR *text);
|
|
|
|
|
|
|
|
|
|
// Check the next token to see if it's an identifier.
|
|
|
|
|
//
|
|
|
|
|
bool IsIdent();
|
|
|
|
|
|
|
|
|
|
// Make a syntax error message, using the tokens.
|
|
|
|
|
//
|
|
|
|
|
void Syntax();
|
|
|
|
|
|
|
|
|
|
// Empty out the FlxParsedProto.
|
|
|
|
|
//
|
|
|
|
|
void Empty();
|
|
|
|
|
|
|
|
|
|
// Parse a function prototype.
|
|
|
|
|
//
|
|
|
|
|
void Parse(const FString &proto);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// Construct with a prototype.
|
|
|
|
|
//
|
|
|
|
|
FlxParsedProto(const FString &str) { Parse(str); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// To make a Lua Call from inside of a blueprint, use the convenient "Call Lua"
|
|
|
|
|
// blueprint node. This node macroexpands into a sequence of low-level
|
|
|
|
|
// function calls. This library contains the low-level functions that
|
|
|
|
|
// "Call Lua" macroexpands into.
|
2024-08-31 16:42:07 -04:00
|
|
|
//
|
2025-02-26 14:47:53 -05:00
|
|
|
// The procedure for making a lua call using the low-level functions is as follows:
|
2024-08-31 16:42:07 -04:00
|
|
|
//
|
2025-02-26 14:47:53 -05:00
|
|
|
// * Use LuaCallBegin to put the class name and function name into the argument buffer.
|
|
|
|
|
// * Use LuaCallArgumentXXX to put arguments into the argument buffer.
|
|
|
|
|
// * Use LuaCallInvoke or LuaCallProbe to actually make the call.
|
|
|
|
|
// * Use LuaCallReturnValueXXX to fetch return values from the return buffer.
|
|
|
|
|
//
|
|
|
|
|
// The two buffers are basically global variables, they are part of the
|
2025-03-17 18:04:55 -04:00
|
|
|
// LuprexGameModeBase. This is okay because blueprint is single-threaded.
|
2025-02-26 14:47:53 -05:00
|
|
|
//
|
|
|
|
|
// The following three libraries contain all the low-level functions.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
2024-08-31 16:42:07 -04:00
|
|
|
|
|
|
|
|
UCLASS()
|
|
|
|
|
class INTEGRATION_API UlxLuaCallLibrary : public UObject
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
public:
|
2025-02-26 14:47:53 -05:00
|
|
|
// Get an argument packing function or a return value unpacking function.
|
|
|
|
|
//
|
|
|
|
|
static UFunction *GetArgumentPacker(const FString &Type);
|
|
|
|
|
static UFunction *GetReturnValueUnpacker(const FString &Type);
|
|
|
|
|
|
|
|
|
|
// Get the types supported for arguments and return values, as a documentation string.
|
|
|
|
|
//
|
|
|
|
|
static FString AllFunctionsWithPrefix(const TCHAR *Prefix);
|
|
|
|
|
static FString AllKnownArgumentTypes() { return AllFunctionsWithPrefix(TEXT("LuaCallArgument_")); }
|
|
|
|
|
static FString AllKnownReturnValueTypes() { return AllFunctionsWithPrefix(TEXT("LuaCallReturnValue_")); }
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
//
|
|
|
|
|
// Functions that do miscellaneous things.
|
|
|
|
|
//
|
|
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-24 16:46:05 -05:00
|
|
|
static void LuaCallBegin(UObject *context, const FString &ClassName, const FString &FunctionName);
|
2024-08-31 16:42:07 -04:00
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static void LuaCallInvoke(UObject *context, AActor *Place);
|
2025-02-05 16:08:34 -05:00
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static void LuaCallProbe(UObject *context, AActor *Place);
|
|
|
|
|
|
2025-03-28 23:31:44 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
|
|
|
|
static UlxLuaValues *LuaCallGetRest(UObject *context);
|
|
|
|
|
|
2025-02-26 14:47:53 -05:00
|
|
|
//
|
|
|
|
|
// Functions that pack arguments into the call buffer.
|
|
|
|
|
//
|
2024-08-31 16:42:07 -04:00
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static void LuaCallArgument_string(UObject *context, const FString &Value);
|
2025-02-24 16:46:05 -05:00
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static void LuaCallArgument_name(UObject *context, const FName &Value);
|
2025-02-24 16:46:05 -05:00
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static void LuaCallArgument_float(UObject *context, double Value);
|
|
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static void LuaCallArgument_int(UObject *context, int Value);
|
2024-08-31 16:42:07 -04:00
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static void LuaCallArgument_vector(UObject *context, const FVector &Value);
|
2024-09-05 01:33:37 -04:00
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static void LuaCallArgument_vector2d(UObject *context, const FVector2D &Value);
|
2024-09-05 01:33:37 -04:00
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static void LuaCallArgument_boolean(UObject *context, bool Value);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Functions that extract return values from the return buffer.
|
|
|
|
|
//
|
|
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static FString LuaCallReturnValue_string(UObject *context);
|
2024-09-05 01:33:37 -04:00
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static FName LuaCallReturnValue_name(UObject *context);
|
2025-02-05 16:08:34 -05:00
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static double LuaCallReturnValue_float(UObject *context);
|
2024-09-05 01:33:37 -04:00
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static int LuaCallReturnValue_int(UObject *context);
|
2024-09-05 01:33:37 -04:00
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static FVector LuaCallReturnValue_vector(UObject *context);
|
|
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static FVector2D LuaCallReturnValue_vector2d(UObject *context);
|
|
|
|
|
|
2025-03-19 16:01:38 -04:00
|
|
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
|
2025-02-26 14:47:53 -05:00
|
|
|
static bool LuaCallReturnValue_boolean(UObject *context);
|
2024-08-31 16:42:07 -04:00
|
|
|
};
|
|
|
|
|
|
2025-02-26 14:47:53 -05:00
|
|
|
|