aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compat.h46
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
236template <typename LUA_RESUME>
237concept RequiresLuaResume51 = requires(LUA_RESUME f_) { { f_(nullptr, 0) } -> std::same_as<int>; };
238
239template <RequiresLuaResume51 LUA_RESUME>
240static 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
250template <typename LUA_RESUME>
251concept RequiresLuaResume52 = requires(LUA_RESUME f_) { { f_(nullptr, nullptr, 0) } -> std::same_as<int>; };
252
253template <RequiresLuaResume52 LUA_RESUME>
254static 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
264template <typename LUA_RESUME>
265concept RequiresLuaResume54 = requires(LUA_RESUME f_) { { f_(nullptr, nullptr, 0, nullptr) } -> std::same_as<int>; };
266
267template <RequiresLuaResume54 LUA_RESUME>
268static 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
275static 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
236template <size_t N> 282template <size_t N>
237static inline void luaG_newlib(lua_State* const L_, luaL_Reg const (&funcs_)[N]) 283static inline void luaG_newlib(lua_State* const L_, luaL_Reg const (&funcs_)[N])
238{ 284{