diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/compat.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/compat.h b/src/compat.h index 1789a8b..58af985 100644 --- a/src/compat.h +++ b/src/compat.h | |||
| @@ -172,10 +172,22 @@ struct Wrap | |||
| 172 | return ::lua_dump(L_, writer_, data_, strip_); | 172 | return ::lua_dump(L_, writer_, data_, strip_); |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | template <size_t N> | ||
| 176 | static inline void (luaL_newlib)(lua_State* const L_, luaL_Reg const (&funcs_)[N]) | ||
| 177 | { | ||
| 178 | lua_createtable(L_, 0, N - 1); | ||
| 179 | ::luaL_setfuncs(L_, funcs_, 0); | ||
| 180 | } | ||
| 181 | |||
| 175 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int nup_) | 182 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int nup_) |
| 176 | { | 183 | { |
| 177 | ::luaL_setfuncs(L_, funcs_, nup_); | 184 | ::luaL_setfuncs(L_, funcs_, nup_); |
| 178 | } | 185 | } |
| 186 | |||
| 187 | static void luaL_setmetatable(lua_State* const L_, std::string_view const& tname_) | ||
| 188 | { | ||
| 189 | ::luaL_setmetatable(L_, tname_.data()); | ||
| 190 | } | ||
| 179 | }; | 191 | }; |
| 180 | 192 | ||
| 181 | // ################################################################################################# | 193 | // ################################################################################################# |
| @@ -188,10 +200,22 @@ struct Wrap<VERSION, typename std::enable_if<VERSION == 503>::type> | |||
| 188 | return ::lua_dump(L_, writer_, data_, strip_); | 200 | return ::lua_dump(L_, writer_, data_, strip_); |
| 189 | } | 201 | } |
| 190 | 202 | ||
| 203 | template <size_t N> | ||
| 204 | static inline void (luaL_newlib)(lua_State* const L_, luaL_Reg const (&funcs_)[N]) | ||
| 205 | { | ||
| 206 | lua_createtable(L_, 0, N - 1); | ||
| 207 | ::luaL_setfuncs(L_, funcs_, 0); | ||
| 208 | } | ||
| 209 | |||
| 191 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int const nup_) | 210 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int const nup_) |
| 192 | { | 211 | { |
| 193 | ::luaL_setfuncs(L_, funcs_, nup_); | 212 | ::luaL_setfuncs(L_, funcs_, nup_); |
| 194 | } | 213 | } |
| 214 | |||
| 215 | static void luaL_setmetatable(lua_State* const L_, std::string_view const& tname_) | ||
| 216 | { | ||
| 217 | ::luaL_setmetatable(L_, tname_.data()); | ||
| 218 | } | ||
| 195 | }; | 219 | }; |
| 196 | 220 | ||
| 197 | // ################################################################################################# | 221 | // ################################################################################################# |
| @@ -204,10 +228,22 @@ struct Wrap<VERSION, typename std::enable_if<VERSION == 502>::type> | |||
| 204 | return ::lua_dump(L_, writer_, data_); | 228 | return ::lua_dump(L_, writer_, data_); |
| 205 | } | 229 | } |
| 206 | 230 | ||
| 231 | template <size_t N> | ||
| 232 | static inline void (luaL_newlib)(lua_State* const L_, luaL_Reg const (&funcs_)[N]) | ||
| 233 | { | ||
| 234 | lua_createtable(L_, 0, N - 1); | ||
| 235 | ::luaL_setfuncs(L_, funcs_, 0); | ||
| 236 | } | ||
| 237 | |||
| 207 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int const nup_) | 238 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int const nup_) |
| 208 | { | 239 | { |
| 209 | ::luaL_setfuncs(L_, funcs_, nup_); | 240 | ::luaL_setfuncs(L_, funcs_, nup_); |
| 210 | } | 241 | } |
| 242 | |||
| 243 | static void luaL_setmetatable(lua_State* const L_, std::string_view const& tname_) | ||
| 244 | { | ||
| 245 | ::luaL_setmetatable(L_, tname_.data()); | ||
| 246 | } | ||
| 211 | }; | 247 | }; |
| 212 | 248 | ||
| 213 | // ################################################################################################# | 249 | // ################################################################################################# |
| @@ -220,10 +256,23 @@ struct Wrap<VERSION, typename std::enable_if<VERSION == 501>::type> | |||
| 220 | return ::lua_dump(L_, writer_, data_); | 256 | return ::lua_dump(L_, writer_, data_); |
| 221 | } | 257 | } |
| 222 | 258 | ||
| 259 | template<size_t N> | ||
| 260 | static inline void (luaL_newlib)(lua_State* const L_, luaL_Reg const (&funcs_)[N]) | ||
| 261 | { | ||
| 262 | lua_createtable(L_, 0, N - 1); | ||
| 263 | ::luaL_register(L_, nullptr, funcs_); | ||
| 264 | } | ||
| 265 | |||
| 223 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], [[maybe_unused]] int const nup_) | 266 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], [[maybe_unused]] int const nup_) |
| 224 | { | 267 | { |
| 225 | ::luaL_register(L_, nullptr, funcs_); | 268 | ::luaL_register(L_, nullptr, funcs_); |
| 226 | } | 269 | } |
| 270 | |||
| 271 | static void luaL_setmetatable(lua_State* const L_, std::string_view const& tname_) | ||
| 272 | { | ||
| 273 | luaL_getmetatable(L_, tname_.data()); | ||
| 274 | lua_setmetatable(L_, -2); | ||
| 275 | } | ||
| 227 | }; | 276 | }; |
| 228 | 277 | ||
| 229 | // ################################################################################################# | 278 | // ################################################################################################# |
| @@ -248,11 +297,26 @@ LuaType luaG_getmodule(lua_State* L_, std::string_view const& name_); | |||
| 248 | 297 | ||
| 249 | // ------------------------------------------------------------------------------------------------- | 298 | // ------------------------------------------------------------------------------------------------- |
| 250 | 299 | ||
| 300 | template<size_t N> | ||
| 301 | inline void luaG_newlib(lua_State* const L_, luaL_Reg const (&funcs_)[N]) | ||
| 302 | { | ||
| 303 | (Wrap<LUA_VERSION_NUM>::luaL_newlib)(L_, funcs_); | ||
| 304 | } | ||
| 305 | |||
| 306 | // ------------------------------------------------------------------------------------------------- | ||
| 307 | |||
| 251 | inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const funcs_[]) | 308 | inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const funcs_[]) |
| 252 | { | 309 | { |
| 253 | Wrap<LUA_VERSION_NUM>::luaL_setfuncs(L_, funcs_, 0); | 310 | Wrap<LUA_VERSION_NUM>::luaL_setfuncs(L_, funcs_, 0); |
| 254 | } | 311 | } |
| 255 | 312 | ||
| 313 | // ------------------------------------------------------------------------------------------------- | ||
| 314 | |||
| 315 | inline void luaG_setmetatable(lua_State* const L_, std::string_view const& tname_) | ||
| 316 | { | ||
| 317 | return Wrap<LUA_VERSION_NUM>::luaL_setmetatable(L_, tname_); | ||
| 318 | } | ||
| 319 | |||
| 256 | // ################################################################################################# | 320 | // ################################################################################################# |
| 257 | 321 | ||
| 258 | // must keep as a macro as long as we do constant string concatenations | 322 | // must keep as a macro as long as we do constant string concatenations |
