Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Source/LuaMachine/Private/LuaBlueprintFunctionLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2033,3 +2033,40 @@ ULuaState* ULuaBlueprintFunctionLibrary::CreateDynamicLuaState(UObject* WorldCon

return NewLuaState->GetLuaState(WorldContextObject->GetWorld());
}
FLuaValue ULuaBlueprintFunctionLibrary::LuaStateRunFile(UObject* WorldContextObject, ULuaState* State, const FString& Filename, const bool bIgnoreNonExistent)
{
FLuaValue ReturnValue;

if (!State->RunFile(Filename, bIgnoreNonExistent, 1))
{
if (State->bLogError)
State->LogError(State->LastError);
State->ReceiveLuaError(State->LastError);
}
else
{
ReturnValue = State->ToLuaValue(-1);
}

State->Pop();
return ReturnValue;
}
FLuaValue ULuaBlueprintFunctionLibrary::LuaStateGlobalCall(UObject* WorldContextObject, ULuaState* State, const FString& Name, TArray<FLuaValue> Args)
{
FLuaValue ReturnValue;
int32 ItemsToPop = State->GetFieldFromTree(Name);

int NArgs = 0;
for (FLuaValue& Arg : Args)
{
State->FromLuaValue(Arg);
NArgs++;
}

State->PCall(NArgs, ReturnValue);

// we have the return value and the function has been removed, so we do not need to change ItemsToPop
State->Pop(ItemsToPop);

return ReturnValue;
}
5 changes: 5 additions & 0 deletions Source/LuaMachine/Public/LuaBlueprintFunctionLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ class LUAMACHINE_API ULuaBlueprintFunctionLibrary : public UBlueprintFunctionLib
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject"), Category = "Lua")
static ULuaState* CreateDynamicLuaState(UObject* WorldContextObject, TSubclassOf<ULuaState> LuaStateClass);

UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", AutoCreateRefTerm = "Args"), Category = "Lua")
static FLuaValue LuaStateGlobalCall(UObject* WorldContextObject, ULuaState* State, const FString& Name, TArray<FLuaValue> Args);

UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject"), Category = "Lua")
static FLuaValue LuaStateRunFile(UObject* WorldContextObject, ULuaState* State, const FString& Filename, const bool bIgnoreNonExistent);
private:
static void HttpRequestDone(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful, TSubclassOf<ULuaState> LuaState, TWeakObjectPtr<UWorld> World, const FString SecurityHeader, const FString SignaturePublicExponent, const FString SignatureModulus, FLuaHttpSuccess Completed);
static void HttpGenericRequestDone(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful, TWeakPtr<FLuaSmartReference> Context, FLuaHttpResponseReceived ResponseReceived, FLuaHttpError Error);
Expand Down