Skip to content

Commit

Permalink
improved syntax highlighter, added multiple return values to ULuaComp…
Browse files Browse the repository at this point in the history
…onent
  • Loading branch information
rdeioris committed Dec 19, 2018
1 parent 9f15674 commit d40369c
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 2 deletions.
Binary file modified Content/Code/TestMainCode.uasset
Binary file not shown.
Binary file modified Content/LuaMachine_Tests.umap
Binary file not shown.
Binary file modified Content/Tests/TestActorMethodMultiNoArgs.uasset
Binary file not shown.
Binary file not shown.
Binary file modified Content/Tests/TestCoroutineResumeMulti.uasset
Binary file not shown.
Binary file added Content/Tests/TestGC.uasset
Binary file not shown.
62 changes: 61 additions & 1 deletion Source/LuaMachine/Private/LuaComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ FLuaValue ULuaComponent::LuaCallValue(FLuaValue Value, TArray<FLuaValue> Args)
if (!L)
return ReturnValue;

// push function
L->FromLuaValue(Value);
// push component pointer as userdata
L->NewUObject(this);
Expand All @@ -233,7 +234,66 @@ FLuaValue ULuaComponent::LuaCallValue(FLuaValue Value, TArray<FLuaValue> Args)
NArgs++;
}

L->PCall(NArgs, ReturnValue);
if (!L->PCall(NArgs, ReturnValue))
{
if (L->InceptionLevel == 0)
{
if (bLogError)
L->LogError(L->LastError);
OnLuaError.Broadcast(L->LastError);
}
}

L->Pop();

return ReturnValue;
}

TArray<FLuaValue> ULuaComponent::LuaCallValueMulti(FLuaValue Value, TArray<FLuaValue> Args)
{
TArray<FLuaValue> ReturnValue;

ULuaState* L = Value.LuaState;
if (!L)
return ReturnValue;

// push function
L->FromLuaValue(Value);
int32 StackTop = L->GetTop();

// push component pointer as userdata
L->NewUObject(this);
SetupMetatable();

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

FLuaValue LastReturnValue;
if (!L->PCall(NArgs, LastReturnValue, LUA_MULTRET))
{
if (L->InceptionLevel == 0)
{
if (bLogError)
L->LogError(L->LastError);
OnLuaError.Broadcast(L->LastError);
}
}
else
{
int32 NumOfReturnValues = (L->GetTop() - StackTop) + 1;
if (NumOfReturnValues > 0)
{
for (int32 i = -1; i >= -(NumOfReturnValues); i--)
{
ReturnValue.Insert(L->ToLuaValue(i), 0);
}
L->Pop(NumOfReturnValues - 1);
}
}

L->Pop();

Expand Down
3 changes: 3 additions & 0 deletions Source/LuaMachine/Public/LuaComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class LUAMACHINE_API ULuaComponent : public UActorComponent
UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "Args"))
TArray<FLuaValue> LuaCallFunctionMulti(FString Name, TArray<FLuaValue> Args, bool bGlobal);

UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "Args"))
TArray<FLuaValue> LuaCallValueMulti(FLuaValue Value, TArray<FLuaValue> Args);

UFUNCTION(BlueprintCallable, BlueprintPure)
FLuaValue LuaGetField(FString Name);

Expand Down
2 changes: 1 addition & 1 deletion Source/LuaMachineEditor/Private/LuaCodeCustomization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class FLuaMachineSyntaxHighlighterTextLayoutMarshaller : public FSyntaxHighlight
CurrentBlockStyle = SyntaxTextStyle.NilTextStyle;
ParseState = EParseState::None;
}
else if (!TChar<WIDECHAR>::IsAlpha(NextChar) && !TChar<WIDECHAR>::IsDigit(NextChar) && !TChar<WIDECHAR>::IsAlpha(PrevChar) && !TChar<WIDECHAR>::IsDigit(PrevChar))
else if (!TChar<WIDECHAR>::IsAlpha(NextChar) && !TChar<WIDECHAR>::IsDigit(NextChar) && !TChar<WIDECHAR>::IsAlpha(PrevChar) && !TChar<WIDECHAR>::IsDigit(PrevChar) && NextChar != TCHAR('_') && PrevChar != TCHAR('_'))
{
RunInfo.Name = TEXT("SyntaxHighlight.LuaMachine.Keyword");
CurrentBlockStyle = SyntaxTextStyle.KeywordTextStyle;
Expand Down

0 comments on commit d40369c

Please sign in to comment.