diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-07-02 18:00:45 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-07-02 18:00:45 +0200 |
commit | 658556f3f20ed4d8663777ce4955ee885d863ba9 (patch) | |
tree | a4caafb79e1286c350b105fc08ce70f7e2e35210 /src | |
parent | 7c3400f46aa7b341cab557c734326a6a0d8907a8 (diff) | |
download | lanes-658556f3f20ed4d8663777ce4955ee885d863ba9.tar.gz lanes-658556f3f20ed4d8663777ce4955ee885d863ba9.tar.bz2 lanes-658556f3f20ed4d8663777ce4955ee885d863ba9.zip |
Wrap lua_resume for compatibility
Diffstat (limited to '')
-rw-r--r-- | src/compat.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/compat.h b/src/compat.h index 41c8ea9..23dbc03 100644 --- a/src/compat.h +++ b/src/compat.h | |||
@@ -233,6 +233,52 @@ inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const* funcs_) | |||
233 | 233 | ||
234 | // ################################################################################################# | 234 | // ################################################################################################# |
235 | 235 | ||
236 | template <typename LUA_RESUME> | ||
237 | concept RequiresLuaResume51 = requires(LUA_RESUME f_) { { f_(nullptr, 0) } -> std::same_as<int>; }; | ||
238 | |||
239 | template <RequiresLuaResume51 LUA_RESUME> | ||
240 | static inline int WrapLuaResume(LUA_RESUME const f_, lua_State* const L_, [[maybe_unused]] lua_State* const from_, int const nargs_, int* const nresults_) | ||
241 | { | ||
242 | int const _resultsStart{ lua_gettop(L_) - nargs_ - 1 }; | ||
243 | int const _rc{ f_(L_, nargs_) }; | ||
244 | *nresults_ = lua_gettop(L_) - _resultsStart; | ||
245 | return _rc; | ||
246 | } | ||
247 | |||
248 | // ------------------------------------------------------------------------------------------------- | ||
249 | |||
250 | template <typename LUA_RESUME> | ||
251 | concept RequiresLuaResume52 = requires(LUA_RESUME f_) { { f_(nullptr, nullptr, 0) } -> std::same_as<int>; }; | ||
252 | |||
253 | template <RequiresLuaResume52 LUA_RESUME> | ||
254 | static inline int WrapLuaResume(LUA_RESUME const f_, lua_State* const L_, lua_State* const from_, int const nargs_, [[maybe_unused]] int* const nresults_) | ||
255 | { | ||
256 | int const _resultsStart{ lua_gettop(L_) - nargs_ - 1 }; | ||
257 | int const _rc{ f_(L_, from_, nargs_) }; | ||
258 | *nresults_ = lua_gettop(L_) - _resultsStart; | ||
259 | return _rc; | ||
260 | } | ||
261 | |||
262 | // ------------------------------------------------------------------------------------------------- | ||
263 | |||
264 | template <typename LUA_RESUME> | ||
265 | concept RequiresLuaResume54 = requires(LUA_RESUME f_) { { f_(nullptr, nullptr, 0, nullptr) } -> std::same_as<int>; }; | ||
266 | |||
267 | template <RequiresLuaResume54 LUA_RESUME> | ||
268 | static inline int WrapLuaResume(LUA_RESUME const f_, lua_State* const L_, lua_State* const from_, int const nargs_, int* const nresults_) | ||
269 | { | ||
270 | return f_(L_, from_, nargs_, nresults_); | ||
271 | } | ||
272 | |||
273 | // ------------------------------------------------------------------------------------------------- | ||
274 | |||
275 | static inline LuaError luaG_resume(lua_State* const L_, lua_State* const from_, int const nargs_, int* const nresults_) | ||
276 | { | ||
277 | return ToLuaError(WrapLuaResume(lua_resume, L_, from_, nargs_, nresults_)); | ||
278 | } | ||
279 | |||
280 | // ################################################################################################# | ||
281 | |||
236 | template <size_t N> | 282 | template <size_t N> |
237 | static inline void luaG_newlib(lua_State* const L_, luaL_Reg const (&funcs_)[N]) | 283 | static inline void luaG_newlib(lua_State* const L_, luaL_Reg const (&funcs_)[N]) |
238 | { | 284 | { |