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
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[{*.h,*.c,*.cpp,*.cs}]
charset = utf-8
end_of_line = lf
indent_size = 4
tab_width = 4
indent_style = tab
insert_final_newline = true
max_line_length = 140
36 changes: 26 additions & 10 deletions Source/LuaMachine/Private/LuaComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ FLuaValue ULuaComponent::LuaCallFunction(const FString& Name, TArray<FLuaValue>

int32 ItemsToPop = L->GetFieldFromTree(Name, bGlobal);

bool bAddSelfArg = bImplicitSelfForLuaCalls && bImplicitSelf;
// first argument (self/actor)
L->PushValue(-(ItemsToPop + 1));
int NArgs = 1;
if (bAddSelfArg)
{
L->PushValue(-(ItemsToPop + 1));
}
int NArgs = bAddSelfArg ? 1 : 0;
Comment on lines +114 to +120
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check that I'm not doing it wrong here; see line 108

for (FLuaValue& Arg : Args)
{
L->FromLuaValue(Arg);
Expand Down Expand Up @@ -151,9 +155,13 @@ TArray<FLuaValue> ULuaComponent::LuaCallFunctionMulti(FString Name, TArray<FLuaV
int32 ItemsToPop = L->GetFieldFromTree(Name, bGlobal);
int32 StackTop = L->GetTop();

bool bAddSelfArg = bImplicitSelfForLuaCalls && bImplicitSelf;
// first argument (self/actor)
L->PushValue(-(ItemsToPop + 1));
int NArgs = 1;
if (bAddSelfArg)
{
L->PushValue(-(ItemsToPop + 1));
}
int NArgs = bAddSelfArg ? 1 : 0;
Comment on lines +158 to +164
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, see line 151

for (FLuaValue& Arg : Args)
{
L->FromLuaValue(Arg);
Expand Down Expand Up @@ -199,11 +207,15 @@ FLuaValue ULuaComponent::LuaCallValue(FLuaValue Value, TArray<FLuaValue> Args)

// push function
L->FromLuaValue(Value);
bool bAddSelfArg = bImplicitSelfForLuaCalls && bImplicitSelf;
// push component pointer as userdata
L->NewUObject(this, nullptr);
if (bAddSelfArg)
{
L->NewUObject(this, nullptr);
}
L->SetupAndAssignUserDataMetatable(this, Metatable, nullptr);

int NArgs = 1;
int NArgs = bAddSelfArg ? 1 : 0;
for (FLuaValue& Arg : Args)
{
L->FromLuaValue(Arg);
Expand Down Expand Up @@ -282,11 +294,15 @@ TArray<FLuaValue> ULuaComponent::LuaCallValueMulti(FLuaValue Value, TArray<FLuaV
L->FromLuaValue(Value);
int32 StackTop = L->GetTop();

// push component pointer as userdata
L->NewUObject(this, nullptr);
bool bAddSelfArg = bImplicitSelfForLuaCalls && bImplicitSelf;
if (bAddSelfArg)
{
// push component pointer as userdata
L->NewUObject(this, nullptr);
}
L->SetupAndAssignUserDataMetatable(this, Metatable, nullptr);

int NArgs = 1;
int NArgs = bAddSelfArg ? 1 : 0;
for (FLuaValue& Arg : Args)
{
L->FromLuaValue(Arg);
Expand Down Expand Up @@ -374,4 +390,4 @@ FLuaValue ULuaComponent::ReceiveLuaMetaIndex_Implementation(FLuaValue Key)
bool ULuaComponent::ReceiveLuaMetaNewIndex_Implementation(FLuaValue Key, FLuaValue Value)
{
return false;
}
}
18 changes: 17 additions & 1 deletion Source/LuaMachine/Public/LuaComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,25 @@ class LUAMACHINE_API ULuaComponent : public UActorComponent
UPROPERTY(EditAnywhere, Category="Lua")
bool bLogError;

UPROPERTY(EditAnywhere, Category = "Lua")
/**
* Whether to implicitly pass this component as the first argument (usually <code>self</code> when calling a Lua
* function.
*
* Currently, this is only respected by <code>ULuaState::MetaTableFunction__call</code> and
* <code>ULuaState::MetaTableFunction__rawcall</code>. If you want this to work for <code>LuaCall...</code> functions
* as well, you need to enable <code>bImplicitSelfForFunctionCalls</code>, too.
*/
UPROPERTY(EditAnywhere, Category = "Lua")
bool bImplicitSelf;

/**
* When enabled, <code>bImplicitSelf</code> will be respected by all <code>LuaCall...</code> functions.
*
* See <a href="https://github.com/rdeioris/LuaMachine/pull/77">this PR</a>.
*/
UPROPERTY(EditAnywhere, Category = "Lua")
bool bImplicitSelfForLuaCalls;

UPROPERTY(EditAnywhere, Category = "Lua")
TArray<FString> GlobalNames;

Expand Down