Skip to content

Commit 6998316

Browse files
committed
refactor(Lua): moves new virtual overloads to avoid abi breaking
refactors make_hook api to not return a pair with an unused variable for the 90% use case
1 parent 083c2dc commit 6998316

File tree

3 files changed

+132
-130
lines changed

3 files changed

+132
-130
lines changed

UE4SS/include/Mod/CppUserModBase.hpp

Lines changed: 52 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -66,161 +66,141 @@ namespace RC
6666
}
6767

6868
/**
69-
* Executes after a Lua mod is started.
70-
* Executes for every Lua mod that is starting.
69+
* Executes after a Lua mod is started (DEPRECATED).
70+
* @deprecated Use the overload with LuaMadeSimple::Lua* hook_lua instead. This overload may be removed in the next release.
7171
* @param mod_name This is the name of the Lua mod that was started.
7272
* @param lua This is the main Lua instance.
7373
* @param main_lua This is the main Lua thread instance.
7474
* @param async_lua This is the Lua instance for asynchronous things like ExecuteAsync and ExecuteWithDelay.
75-
* @param hook_lua This is the Lua instance that is used for game-thread hooks like ExecuteInGameThread.
75+
* @param hook_luas DEPRECATED: This container previously held multiple hook Lua instances. Now only one hook instance is used.
7676
*/
77+
[[deprecated("The hook_luas vector parameter is deprecated. Use the single hook_lua pointer overload instead. This overload may be removed in the next release")]]
7778
RC_UE4SS_API virtual auto on_lua_start(StringViewType mod_name,
7879
LuaMadeSimple::Lua& lua,
7980
LuaMadeSimple::Lua& main_lua,
8081
LuaMadeSimple::Lua& async_lua,
81-
LuaMadeSimple::Lua* hook_lua) -> void
82+
std::vector<LuaMadeSimple::Lua*>& hook_luas) -> void
8283
{
8384
}
8485

8586
/**
86-
* Executes after a Lua mod is started (DEPRECATED).
87+
* Executes after a Lua mod of the same name is started (DEPRECATED).
8788
* @deprecated Use the overload with LuaMadeSimple::Lua* hook_lua instead. This overload may be removed in the next release.
88-
* @param mod_name This is the name of the Lua mod that was started.
8989
* @param lua This is the main Lua instance.
9090
* @param main_lua This is the main Lua thread instance.
9191
* @param async_lua This is the Lua instance for asynchronous things like ExecuteAsync and ExecuteWithDelay.
9292
* @param hook_luas DEPRECATED: This container previously held multiple hook Lua instances. Now only one hook instance is used.
9393
*/
94-
[[deprecated(
95-
"The hook_luas vector parameter is deprecated. Use the single hook_lua pointer overload instead. This overload may be removed in the next release"
96-
)]
97-
]
98-
RC_UE4SS_API virtual auto on_lua_start(StringViewType mod_name,
99-
LuaMadeSimple::Lua& lua,
94+
[[deprecated("The hook_luas vector parameter is deprecated. Use the single hook_lua pointer overload instead. This overload may be removed in the next release")]]
95+
RC_UE4SS_API virtual auto on_lua_start(LuaMadeSimple::Lua& lua,
10096
LuaMadeSimple::Lua& main_lua,
10197
LuaMadeSimple::Lua& async_lua,
10298
std::vector<LuaMadeSimple::Lua*>& hook_luas) -> void
10399
{
104-
LuaMadeSimple::Lua* hook_lua = hook_luas.empty() ? nullptr : hook_luas[0];
105-
on_lua_start(mod_name, lua, main_lua, async_lua, hook_lua);
106100
}
107101

108102
/**
109-
* Executes after a Lua mod of the same name is started.
103+
* Executes before a Lua mod is about to be stopped (DEPRECATED).
104+
* @deprecated Use the overload with LuaMadeSimple::Lua* hook_lua instead. This overload may be removed in the next release.
105+
* @param mod_name This is the name of the Lua mod that is about to be stopped.
110106
* @param lua This is the main Lua instance.
111107
* @param main_lua This is the main Lua thread instance.
112108
* @param async_lua This is the Lua instance for asynchronous things like ExecuteAsync and ExecuteWithDelay.
113-
* @param hook_lua This is the Lua instance that is used for game-thread hooks like ExecuteInGameThread.
109+
* @param hook_luas DEPRECATED: This container previously held multiple hook Lua instances. Now only one hook instance is used.
114110
*/
115-
RC_UE4SS_API virtual auto on_lua_start(LuaMadeSimple::Lua& lua,
116-
LuaMadeSimple::Lua& main_lua,
117-
LuaMadeSimple::Lua& async_lua,
118-
LuaMadeSimple::Lua* hook_lua) -> void
111+
[[deprecated("The hook_luas vector parameter is deprecated. Use the single hook_lua pointer overload instead. This overload may be removed in the next release")]]
112+
RC_UE4SS_API virtual auto on_lua_stop(StringViewType mod_name,
113+
LuaMadeSimple::Lua& lua,
114+
LuaMadeSimple::Lua& main_lua,
115+
LuaMadeSimple::Lua& async_lua,
116+
std::vector<LuaMadeSimple::Lua*>& hook_luas) -> void
119117
{
120118
}
121119

122120
/**
123-
* Executes after a Lua mod of the same name is started (DEPRECATED).
121+
* Executes before a Lua mod of the same name is about to be stopped (DEPRECATED).
124122
* @deprecated Use the overload with LuaMadeSimple::Lua* hook_lua instead. This overload may be removed in the next release.
125123
* @param lua This is the main Lua instance.
126124
* @param main_lua This is the main Lua thread instance.
127125
* @param async_lua This is the Lua instance for asynchronous things like ExecuteAsync and ExecuteWithDelay.
128126
* @param hook_luas DEPRECATED: This container previously held multiple hook Lua instances. Now only one hook instance is used.
129127
*/
130-
[[deprecated(
131-
"The hook_luas vector parameter is deprecated. Use the single hook_lua pointer overload instead. This overload may be removed in the next release"
132-
)]
133-
]
134-
RC_UE4SS_API virtual auto on_lua_start(LuaMadeSimple::Lua& lua,
135-
LuaMadeSimple::Lua& main_lua,
136-
LuaMadeSimple::Lua& async_lua,
137-
std::vector<LuaMadeSimple::Lua*>& hook_luas) -> void
128+
[[deprecated("The hook_luas vector parameter is deprecated. Use the single hook_lua pointer overload instead. This overload may be removed in the next release")]]
129+
RC_UE4SS_API virtual auto on_lua_stop(LuaMadeSimple::Lua& lua,
130+
LuaMadeSimple::Lua& main_lua,
131+
LuaMadeSimple::Lua& async_lua,
132+
std::vector<LuaMadeSimple::Lua*>& hook_luas) -> void
133+
{
134+
}
135+
136+
RC_UE4SS_API virtual auto on_dll_load(StringViewType dll_name) -> void
138137
{
139-
LuaMadeSimple::Lua* hook_lua = hook_luas.empty() ? nullptr : hook_luas[0];
140-
on_lua_start(lua, main_lua, async_lua, hook_lua);
141138
}
142139

140+
RC_UE4SS_API virtual auto render_tab() -> void {};
141+
143142
/**
144-
* Executes before a Lua mod is about to be stopped.
145-
* Executes for every Lua mod that is stopping.
146-
* @param mod_name This is the name of the Lua mod that is about to be stopped.
143+
* Executes after a Lua mod is started.
144+
* Executes for every Lua mod that is starting.
145+
* @param mod_name This is the name of the Lua mod that was started.
147146
* @param lua This is the main Lua instance.
148147
* @param main_lua This is the main Lua thread instance.
149148
* @param async_lua This is the Lua instance for asynchronous things like ExecuteAsync and ExecuteWithDelay.
150149
* @param hook_lua This is the Lua instance that is used for game-thread hooks like ExecuteInGameThread.
151150
*/
152-
RC_UE4SS_API virtual auto on_lua_stop(StringViewType mod_name,
153-
LuaMadeSimple::Lua& lua,
154-
LuaMadeSimple::Lua& main_lua,
155-
LuaMadeSimple::Lua& async_lua,
156-
LuaMadeSimple::Lua* hook_lua) -> void
151+
RC_UE4SS_API virtual auto on_lua_start(StringViewType mod_name,
152+
LuaMadeSimple::Lua& lua,
153+
LuaMadeSimple::Lua& main_lua,
154+
LuaMadeSimple::Lua& async_lua,
155+
LuaMadeSimple::Lua* hook_lua) -> void
157156
{
158157
}
159158

160159
/**
161-
* Executes before a Lua mod is about to be stopped (DEPRECATED).
162-
* @deprecated Use the overload with LuaMadeSimple::Lua* hook_lua instead. This overload may be removed in the next release.
163-
* @param mod_name This is the name of the Lua mod that is about to be stopped.
160+
* Executes after a Lua mod of the same name is started.
164161
* @param lua This is the main Lua instance.
165162
* @param main_lua This is the main Lua thread instance.
166163
* @param async_lua This is the Lua instance for asynchronous things like ExecuteAsync and ExecuteWithDelay.
167-
* @param hook_luas DEPRECATED: This container previously held multiple hook Lua instances. Now only one hook instance is used.
164+
* @param hook_lua This is the Lua instance that is used for game-thread hooks like ExecuteInGameThread.
168165
*/
169-
[[deprecated(
170-
"The hook_luas vector parameter is deprecated. Use the single hook_lua pointer overload instead. This overload may be removed in the next release"
171-
)]
172-
]
173-
RC_UE4SS_API virtual auto on_lua_stop(StringViewType mod_name,
174-
LuaMadeSimple::Lua& lua,
175-
LuaMadeSimple::Lua& main_lua,
176-
LuaMadeSimple::Lua& async_lua,
177-
std::vector<LuaMadeSimple::Lua*>& hook_luas) -> void
166+
RC_UE4SS_API virtual auto on_lua_start(LuaMadeSimple::Lua& lua,
167+
LuaMadeSimple::Lua& main_lua,
168+
LuaMadeSimple::Lua& async_lua,
169+
LuaMadeSimple::Lua* hook_lua) -> void
178170
{
179-
LuaMadeSimple::Lua* hook_lua = hook_luas.empty() ? nullptr : hook_luas[0];
180-
on_lua_stop(mod_name, lua, main_lua, async_lua, hook_lua);
181171
}
182172

183173
/**
184-
* Executes before a Lua mod of the same name is about to be stopped.
174+
* Executes before a Lua mod is about to be stopped.
175+
* Executes for every Lua mod that is stopping.
176+
* @param mod_name This is the name of the Lua mod that is about to be stopped.
185177
* @param lua This is the main Lua instance.
186178
* @param main_lua This is the main Lua thread instance.
187179
* @param async_lua This is the Lua instance for asynchronous things like ExecuteAsync and ExecuteWithDelay.
188180
* @param hook_lua This is the Lua instance that is used for game-thread hooks like ExecuteInGameThread.
189181
*/
190-
RC_UE4SS_API virtual auto on_lua_stop(LuaMadeSimple::Lua& lua,
182+
RC_UE4SS_API virtual auto on_lua_stop(StringViewType mod_name,
183+
LuaMadeSimple::Lua& lua,
191184
LuaMadeSimple::Lua& main_lua,
192185
LuaMadeSimple::Lua& async_lua,
193186
LuaMadeSimple::Lua* hook_lua) -> void
194187
{
195188
}
196189

197190
/**
198-
* Executes before a Lua mod of the same name is about to be stopped (DEPRECATED).
199-
* @deprecated Use the overload with LuaMadeSimple::Lua* hook_lua instead. This overload may be removed in the next release.
191+
* Executes before a Lua mod of the same name is about to be stopped.
200192
* @param lua This is the main Lua instance.
201193
* @param main_lua This is the main Lua thread instance.
202194
* @param async_lua This is the Lua instance for asynchronous things like ExecuteAsync and ExecuteWithDelay.
203-
* @param hook_luas DEPRECATED: This container previously held multiple hook Lua instances. Now only one hook instance is used.
195+
* @param hook_lua This is the Lua instance that is used for game-thread hooks like ExecuteInGameThread.
204196
*/
205-
[[deprecated(
206-
"The hook_luas vector parameter is deprecated. Use the single hook_lua pointer overload instead. This overload may be removed in the next release"
207-
)]
208-
]
209197
RC_UE4SS_API virtual auto on_lua_stop(LuaMadeSimple::Lua& lua,
210198
LuaMadeSimple::Lua& main_lua,
211199
LuaMadeSimple::Lua& async_lua,
212-
std::vector<LuaMadeSimple::Lua*>& hook_luas) -> void
213-
{
214-
LuaMadeSimple::Lua* hook_lua = hook_luas.empty() ? nullptr : hook_luas[0];
215-
on_lua_stop(lua, main_lua, async_lua, hook_lua);
216-
}
217-
218-
RC_UE4SS_API virtual auto on_dll_load(StringViewType dll_name) -> void
200+
LuaMadeSimple::Lua* hook_lua) -> void
219201
{
220202
}
221203

222-
RC_UE4SS_API virtual auto render_tab() -> void {};
223-
224204
protected:
225205
RC_UE4SS_API auto register_tab(StringViewType tab_name, GUI::GUITab::RenderFunctionType) -> void;
226206
RC_UE4SS_API auto register_keydown_event(Input::Key, const Input::EventCallbackCallable&, uint8_t custom_data = 0) -> void;

UE4SS/src/Mod/CppMod.cpp

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,17 @@ namespace RC
8989
{
9090
if (m_mod)
9191
{
92+
// Call new API
9293
m_mod->on_lua_start(mod_name, lua, main_lua, async_lua, hook_lua);
93-
}
94-
}
9594

96-
auto CppMod::fire_on_lua_start(StringViewType mod_name,
97-
LuaMadeSimple::Lua& lua,
98-
LuaMadeSimple::Lua& main_lua,
99-
LuaMadeSimple::Lua& async_lua,
100-
std::vector<LuaMadeSimple::Lua*>& hook_luas) -> void
101-
{
102-
LuaMadeSimple::Lua* hook_lua = hook_luas.empty() ? nullptr : hook_luas[0];
103-
fire_on_lua_start(mod_name, lua, main_lua, async_lua, hook_lua);
95+
// Call old deprecated API for backwards compatibility
96+
std::vector<LuaMadeSimple::Lua*> hook_luas;
97+
if (hook_lua)
98+
{
99+
hook_luas.push_back(hook_lua);
100+
}
101+
m_mod->on_lua_start(mod_name, lua, main_lua, async_lua, hook_luas);
102+
}
104103
}
105104

106105
auto CppMod::fire_on_lua_start(LuaMadeSimple::Lua& lua,
@@ -110,17 +109,17 @@ namespace RC
110109
{
111110
if (m_mod)
112111
{
112+
// Call new API
113113
m_mod->on_lua_start(lua, main_lua, async_lua, hook_lua);
114-
}
115-
}
116114

117-
auto CppMod::fire_on_lua_start(LuaMadeSimple::Lua& lua,
118-
LuaMadeSimple::Lua& main_lua,
119-
LuaMadeSimple::Lua& async_lua,
120-
std::vector<LuaMadeSimple::Lua*>& hook_luas) -> void
121-
{
122-
LuaMadeSimple::Lua* hook_lua = hook_luas.empty() ? nullptr : hook_luas[0];
123-
fire_on_lua_start(lua, main_lua, async_lua, hook_lua);
115+
// Call old deprecated API for backwards compatibility
116+
std::vector<LuaMadeSimple::Lua*> hook_luas;
117+
if (hook_lua)
118+
{
119+
hook_luas.push_back(hook_lua);
120+
}
121+
m_mod->on_lua_start(lua, main_lua, async_lua, hook_luas);
122+
}
124123
}
125124

126125
auto CppMod::fire_on_lua_stop(StringViewType mod_name,
@@ -131,32 +130,34 @@ namespace RC
131130
{
132131
if (m_mod)
133132
{
133+
// Call new API
134134
m_mod->on_lua_stop(mod_name, lua, main_lua, async_lua, hook_lua);
135-
}
136-
}
137135

138-
auto CppMod::fire_on_lua_stop(StringViewType mod_name,
139-
LuaMadeSimple::Lua& lua,
140-
LuaMadeSimple::Lua& main_lua,
141-
LuaMadeSimple::Lua& async_lua,
142-
std::vector<LuaMadeSimple::Lua*>& hook_luas) -> void
143-
{
144-
LuaMadeSimple::Lua* hook_lua = hook_luas.empty() ? nullptr : hook_luas[0];
145-
fire_on_lua_stop(mod_name, lua, main_lua, async_lua, hook_lua);
136+
// Call old deprecated API for backwards compatibility
137+
std::vector<LuaMadeSimple::Lua*> hook_luas;
138+
if (hook_lua)
139+
{
140+
hook_luas.push_back(hook_lua);
141+
}
142+
m_mod->on_lua_stop(mod_name, lua, main_lua, async_lua, hook_luas);
143+
}
146144
}
147145

148146
auto CppMod::fire_on_lua_stop(LuaMadeSimple::Lua& lua, LuaMadeSimple::Lua& main_lua, LuaMadeSimple::Lua& async_lua, LuaMadeSimple::Lua* hook_lua) -> void
149147
{
150148
if (m_mod)
151149
{
150+
// Call new API
152151
m_mod->on_lua_stop(lua, main_lua, async_lua, hook_lua);
153-
}
154-
}
155152

156-
auto CppMod::fire_on_lua_stop(LuaMadeSimple::Lua& lua, LuaMadeSimple::Lua& main_lua, LuaMadeSimple::Lua& async_lua, std::vector<LuaMadeSimple::Lua*>& hook_luas) -> void
157-
{
158-
LuaMadeSimple::Lua* hook_lua = hook_luas.empty() ? nullptr : hook_luas[0];
159-
fire_on_lua_stop(lua, main_lua, async_lua, hook_lua);
153+
// Call old deprecated API for backwards compatibility
154+
std::vector<LuaMadeSimple::Lua*> hook_luas;
155+
if (hook_lua)
156+
{
157+
hook_luas.push_back(hook_lua);
158+
}
159+
m_mod->on_lua_stop(lua, main_lua, async_lua, hook_luas);
160+
}
160161
}
161162

162163
auto CppMod::fire_unreal_init() -> void

0 commit comments

Comments
 (0)