| 405 | |
| 406 | template <typename T> |
| 407 | T* user_allocate(lua_State* L) { |
| 408 | typedef std::integral_constant<bool, |
| 409 | #if SOL_IS_OFF(SOL_ALIGN_MEMORY) |
| 410 | false |
| 411 | #else |
| 412 | (std::alignment_of_v<T> > 1) |
| 413 | #endif |
| 414 | > |
| 415 | use_align; |
| 416 | if (!use_align::value) { |
| 417 | T* pointer = static_cast<T*>(alloc_newuserdata(L, sizeof(T))); |
| 418 | return pointer; |
| 419 | } |
| 420 | |
| 421 | constexpr std::size_t initial_size = aligned_space_for<T>(); |
| 422 | |
| 423 | std::size_t allocated_size = initial_size; |
| 424 | void* unadjusted = alloc_newuserdata(L, allocated_size); |
| 425 | void* adjusted = align(std::alignment_of_v<T>, unadjusted, allocated_size); |
| 426 | if (adjusted == nullptr) { |
| 427 | lua_pop(L, 1); |
| 428 | luaL_error(L, "cannot properly align memory for '%s'", detail::demangle<T>().data()); |
| 429 | } |
| 430 | return static_cast<T*>(adjusted); |
| 431 | } |
| 432 | |
| 433 | template <typename T> |
| 434 | int usertype_alloc_destroy(lua_State* L) noexcept { |
nothing calls this directly
no test coverage detected