#pragma once #include "CoreMinimal.h" #include "EdGraph/EdGraphPin.h" #include "LuaCall.generated.h" ///////////////////////////////////////////////////////////////// // // These are the types that can actually be packed into // an argument or return value buffer. Any other type is // subject to conversion before packing. // ///////////////////////////////////////////////////////////////// UENUM(BlueprintType) enum class ELpxSimpleDynamicTag : uint8 { None, String, Name, Float, Boolean, Vector }; ///////////////////////////////////////////////////////////////// // // 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 Tokens; int NextToken; FString ClassName; FString FunctionName; TArray Arguments; TArray 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. // // The procedure for making a lua call using the low-level functions is as follows: // // * 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 // LuprexGameModeBase. This is okay because blueprint is single-threaded. // // The following three libraries contain all the low-level functions. // ///////////////////////////////////////////////////////////////// UCLASS() class INTEGRATION_API UlxLuaCallLibrary : public UObject { GENERATED_BODY() public: // 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. // UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static void LuaCallBegin(UObject *context, const FString &ClassName, const FString &FunctionName); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static void LuaCallInvoke(UObject *context, AActor *Place); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static void LuaCallProbe(UObject *context, AActor *Place); // // Functions that pack arguments into the call buffer. // UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static void LuaCallArgument_string(UObject *context, const FString &Value); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static void LuaCallArgument_name(UObject *context, const FName &Value); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static void LuaCallArgument_float(UObject *context, double Value); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static void LuaCallArgument_int(UObject *context, int Value); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static void LuaCallArgument_vector(UObject *context, const FVector &Value); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static void LuaCallArgument_vector2d(UObject *context, const FVector2D &Value); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static void LuaCallArgument_boolean(UObject *context, bool Value); // // Functions that extract return values from the return buffer. // UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static FString LuaCallReturnValue_string(UObject *context); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static FName LuaCallReturnValue_name(UObject *context); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static double LuaCallReturnValue_float(UObject *context); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static int LuaCallReturnValue_int(UObject *context); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static FVector LuaCallReturnValue_vector(UObject *context); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static FVector2D LuaCallReturnValue_vector2d(UObject *context); UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function") static bool LuaCallReturnValue_boolean(UObject *context); };