Skip to content

Commit 30d0a66

Browse files
committed
Add Lua support for SoftObjectProperty
- Renamed TSoftClassProperty to TSoftObjectProperty - Add Lua GetWeakPtr method to retrieve weak pointer from a SoftObjectProperty
1 parent 4acf640 commit 30d0a66

File tree

5 files changed

+35
-28
lines changed

5 files changed

+35
-28
lines changed

UE4SS/include/LuaType/LuaTSoftClassPtr.hpp renamed to UE4SS/include/LuaType/LuaTSoftObjectPtr.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#pragma once
22

33
#include <LuaType/LuaUObject.hpp>
4-
#include <Unreal/Property/FSoftClassProperty.hpp>
4+
#include <Unreal/Property/FSoftObjectProperty.hpp>
55

66
namespace RC::LuaType
77
{
8-
struct TSoftClassPtrName
8+
struct TSoftObjectPtrName
99
{
1010
constexpr static const char* ToString()
1111
{
12-
return "TSoftClassPtr";
12+
return "TSoftObjectPtr";
1313
}
1414
};
15-
class TSoftClassPtr : public LocalObjectBase<Unreal::FSoftObjectPtr, TSoftClassPtrName>
15+
class TSoftObjectPtr : public LocalObjectBase<Unreal::FSoftObjectPtr, TSoftObjectPtrName>
1616
{
1717
private:
18-
explicit TSoftClassPtr(Unreal::FSoftObjectPtr object);
18+
explicit TSoftObjectPtr(Unreal::FSoftObjectPtr object);
1919

2020
public:
21-
TSoftClassPtr() = delete;
21+
TSoftObjectPtr() = delete;
2222
auto static construct(const LuaMadeSimple::Lua&, Unreal::FSoftObjectPtr&) -> const LuaMadeSimple::Lua::Table;
2323
auto static construct(const LuaMadeSimple::Lua&, BaseObject&) -> const LuaMadeSimple::Lua::Table;
2424

UE4SS/include/LuaType/LuaUObject.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ namespace RC::LuaType
384384
RC_UE4SS_API auto push_nameproperty(const PusherParams&) -> void;
385385
RC_UE4SS_API auto push_textproperty(const PusherParams&) -> void;
386386
RC_UE4SS_API auto push_strproperty(const PusherParams&) -> void;
387-
RC_UE4SS_API auto push_softclassproperty(const PusherParams&) -> void;
387+
RC_UE4SS_API auto push_softobjectproperty(const PusherParams&) -> void;
388388
RC_UE4SS_API auto push_interfaceproperty(const PusherParams&) -> void;
389389

390390
RC_UE4SS_API auto push_functionproperty(const FunctionPusherParams&) -> void;
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
#include <Helpers/String.hpp>
33
#include <LuaType/LuaFSoftObjectPath.hpp>
44
#include <LuaType/LuaFWeakObjectPtr.hpp>
5-
#include <LuaType/LuaTSoftClassPtr.hpp>
5+
#include <LuaType/LuaTSoftObjectPtr.hpp>
66

77
namespace RC::LuaType
88
{
9-
TSoftClassPtr::TSoftClassPtr(Unreal::FSoftObjectPtr object) : LocalObjectBase<Unreal::FSoftObjectPtr, TSoftClassPtrName>(std::move(object))
9+
TSoftObjectPtr::TSoftObjectPtr(Unreal::FSoftObjectPtr object) : LocalObjectBase<Unreal::FSoftObjectPtr, TSoftObjectPtrName>(std::move(object))
1010
{
1111
}
1212

13-
auto TSoftClassPtr::construct(const LuaMadeSimple::Lua& lua, Unreal::FSoftObjectPtr& unreal_object) -> const LuaMadeSimple::Lua::Table
13+
auto TSoftObjectPtr::construct(const LuaMadeSimple::Lua& lua, Unreal::FSoftObjectPtr& unreal_object) -> const LuaMadeSimple::Lua::Table
1414
{
15-
LuaType::TSoftClassPtr lua_object{unreal_object};
15+
LuaType::TSoftObjectPtr lua_object{unreal_object};
1616

17-
auto metatable_name = "TSoftClassPtrUserdata";
17+
auto metatable_name = "TSoftObjectPtrUserdata";
1818

1919
LuaMadeSimple::Lua::Table table = lua.get_metatable(metatable_name);
2020
if (lua.is_nil(-1))
@@ -23,7 +23,7 @@ namespace RC::LuaType
2323
lua.prepare_new_table();
2424
setup_metamethods(lua_object);
2525
setup_member_functions<LuaMadeSimple::Type::IsFinal::Yes>(table, metatable_name);
26-
lua.new_metatable<LuaType::TSoftClassPtr>(metatable_name, lua_object.get_metamethods());
26+
lua.new_metatable<LuaType::TSoftObjectPtr>(metatable_name, lua_object.get_metamethods());
2727
}
2828

2929
// Create object & surrender ownership to Lua
@@ -32,42 +32,48 @@ namespace RC::LuaType
3232
return table;
3333
}
3434

35-
auto TSoftClassPtr::construct(const LuaMadeSimple::Lua& lua, BaseObject& construct_to) -> const LuaMadeSimple::Lua::Table
35+
auto TSoftObjectPtr::construct(const LuaMadeSimple::Lua& lua, BaseObject& construct_to) -> const LuaMadeSimple::Lua::Table
3636
{
3737
LuaMadeSimple::Lua::Table table = lua.prepare_new_table();
3838
;
3939

40-
auto metatable_name = "TSoftClassPtrUserdata";
40+
auto metatable_name = "TSoftObjectPtrUserdata";
4141

4242
setup_metamethods(construct_to);
4343
setup_member_functions<LuaMadeSimple::Type::IsFinal::No>(table, metatable_name);
4444

4545
return table;
4646
}
4747

48-
auto TSoftClassPtr::setup_metamethods(BaseObject& base_object) -> void
48+
auto TSoftObjectPtr::setup_metamethods(BaseObject& base_object) -> void
4949
{
5050
}
5151

5252
template <LuaMadeSimple::Type::IsFinal is_final>
53-
auto TSoftClassPtr::setup_member_functions(LuaMadeSimple::Lua::Table& table, std::string_view metatable_name) -> void
53+
auto TSoftObjectPtr::setup_member_functions(LuaMadeSimple::Lua::Table& table, std::string_view metatable_name) -> void
5454
{
55+
table.add_pair("GetWeakPtr", [](const LuaMadeSimple::Lua& lua) -> int {
56+
auto& lua_object = lua.get_userdata<TSoftObjectPtr>();
57+
FWeakObjectPtr::construct(lua, lua_object.get_local_cpp_object().WeakPtr);
58+
return 1;
59+
});
60+
5561
table.add_pair("GetTagAtLastTest", [](const LuaMadeSimple::Lua& lua) -> int {
56-
auto& lua_object = lua.get_userdata<TSoftClassPtr>();
62+
auto& lua_object = lua.get_userdata<TSoftObjectPtr>();
5763
lua.set_integer(lua_object.get_local_cpp_object().TagAtLastTest);
5864
return 1;
5965
});
6066

6167
table.add_pair("GetObjectID", [](const LuaMadeSimple::Lua& lua) -> int {
62-
auto& lua_object = lua.get_userdata<TSoftClassPtr>();
68+
auto& lua_object = lua.get_userdata<TSoftObjectPtr>();
6369
FSoftObjectPath::construct(lua, lua_object.get_local_cpp_object().ObjectID);
6470
return 1;
6571
});
6672

6773
if constexpr (is_final == LuaMadeSimple::Type::IsFinal::Yes)
6874
{
6975
table.add_pair("type", [](const LuaMadeSimple::Lua& lua) -> int {
70-
lua.set_string("TSoftClassPtrUserdata");
76+
lua.set_string("TSoftObjectPtrUserdata");
7177
return 1;
7278
});
7379

UE4SS/src/LuaType/LuaUObject.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <LuaType/LuaTArray.hpp>
99
#include <LuaType/LuaTSet.hpp>
1010
#include <LuaType/LuaTMap.hpp>
11-
#include <LuaType/LuaTSoftClassPtr.hpp>
11+
#include <LuaType/LuaTSoftObjectPtr.hpp>
1212
#include <LuaType/LuaUClass.hpp>
1313
#include <LuaType/LuaUEnum.hpp>
1414
#include <LuaType/LuaUFunction.hpp>
@@ -1655,34 +1655,34 @@ namespace RC::LuaType
16551655
params.throw_error("push_strproperty", "Operation not supported");
16561656
}
16571657

1658-
auto push_softclassproperty(const PusherParams& params) -> void
1658+
auto push_softobjectproperty(const PusherParams& params) -> void
16591659
{
16601660
auto soft_ptr = static_cast<Unreal::FSoftObjectPtr*>(params.data);
16611661
if (!soft_ptr)
16621662
{
1663-
params.throw_error("push_softclassproperty", "data pointer is nullptr");
1663+
params.throw_error("push_softobjectproperty", "data pointer is nullptr");
16641664
}
16651665

16661666
switch (params.operation)
16671667
{
16681668
case Operation::GetNonTrivialLocal:
16691669
case Operation::Get:
1670-
LuaType::TSoftClassPtr::construct(params.lua, *soft_ptr);
1670+
LuaType::TSoftObjectPtr::construct(params.lua, *soft_ptr);
16711671
return;
16721672
case Operation::Set: {
1673-
auto& lua_object = params.lua.get_userdata<LuaType::TSoftClassPtr>(params.stored_at_index);
1673+
auto& lua_object = params.lua.get_userdata<LuaType::TSoftObjectPtr>(params.stored_at_index);
16741674
*soft_ptr = lua_object.get_local_cpp_object();
16751675
return;
16761676
}
16771677
case Operation::GetParam:
16781678
RemoteUnrealParam::construct(params.lua, params.data, params.base, params.property);
16791679
return;
16801680
default:
1681-
params.throw_error("push_softclassproperty", "Unhandled Operation");
1681+
params.throw_error("push_softobjectproperty", "Unhandled Operation");
16821682
break;
16831683
}
16841684

1685-
params.throw_error("push_softclassproperty", "Operation not supported");
1685+
params.throw_error("push_softobjectproperty", "Operation not supported");
16861686
}
16871687

16881688
auto push_interfaceproperty(const PusherParams& params) -> void

UE4SS/src/UE4SSProgram.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,8 @@ namespace RC
11631163
LuaType::StaticState::m_property_value_pushers.emplace(FName(STR("NameProperty")).GetComparisonIndex(), &LuaType::push_nameproperty);
11641164
LuaType::StaticState::m_property_value_pushers.emplace(FName(STR("TextProperty")).GetComparisonIndex(), &LuaType::push_textproperty);
11651165
LuaType::StaticState::m_property_value_pushers.emplace(FName(STR("StrProperty")).GetComparisonIndex(), &LuaType::push_strproperty);
1166-
LuaType::StaticState::m_property_value_pushers.emplace(FName(STR("SoftClassProperty")).GetComparisonIndex(), &LuaType::push_softclassproperty);
1166+
LuaType::StaticState::m_property_value_pushers.emplace(FName(STR("SoftObjectProperty")).GetComparisonIndex(), &LuaType::push_softobjectproperty);
1167+
LuaType::StaticState::m_property_value_pushers.emplace(FName(STR("SoftClassProperty")).GetComparisonIndex(), &LuaType::push_softobjectproperty);
11671168
LuaType::StaticState::m_property_value_pushers.emplace(FName(STR("InterfaceProperty")).GetComparisonIndex(), &LuaType::push_interfaceproperty);
11681169
}
11691170

0 commit comments

Comments
 (0)