diff options
Diffstat (limited to 'src/allocator.hpp')
-rw-r--r-- | src/allocator.hpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/allocator.hpp b/src/allocator.hpp index 4fec044..16db1e6 100644 --- a/src/allocator.hpp +++ b/src/allocator.hpp | |||
@@ -25,8 +25,10 @@ namespace lanes { | |||
25 | 25 | ||
26 | public: | 26 | public: |
27 | 27 | ||
28 | [[nodiscard]] static void* operator new(size_t const size_) noexcept = delete; // can't create one outside of a Lua state | 28 | [[nodiscard]] |
29 | [[nodiscard]] static void* operator new(size_t const size_, lua_State* const L_) noexcept { return lua_newuserdatauv(L_, size_, UserValueCount{ 0 }); } | 29 | static void* operator new(size_t const size_) noexcept = delete; // can't create one outside of a Lua state |
30 | [[nodiscard]] | ||
31 | static void* operator new(size_t const size_, lua_State* const L_) noexcept { return lua_newuserdatauv(L_, size_, UserValueCount{ 0 }); } | ||
30 | // always embedded somewhere else or "in-place constructed" as a full userdata | 32 | // always embedded somewhere else or "in-place constructed" as a full userdata |
31 | // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception | 33 | // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception |
32 | static void operator delete([[maybe_unused]] void* const p_, [[maybe_unused]] lua_State* const L_) {} | 34 | static void operator delete([[maybe_unused]] void* const p_, [[maybe_unused]] lua_State* const L_) {} |
@@ -44,6 +46,7 @@ namespace lanes { | |||
44 | AllocatorDefinition& operator=(AllocatorDefinition const& rhs_) = default; | 46 | AllocatorDefinition& operator=(AllocatorDefinition const& rhs_) = default; |
45 | AllocatorDefinition& operator=(AllocatorDefinition&& rhs_) = default; | 47 | AllocatorDefinition& operator=(AllocatorDefinition&& rhs_) = default; |
46 | 48 | ||
49 | [[nodiscard]] | ||
47 | static AllocatorDefinition& Validated(lua_State* L_, StackIndex idx_); | 50 | static AllocatorDefinition& Validated(lua_State* L_, StackIndex idx_); |
48 | 51 | ||
49 | void initFrom(lua_State* const L_) | 52 | void initFrom(lua_State* const L_) |
@@ -58,16 +61,19 @@ namespace lanes { | |||
58 | } | 61 | } |
59 | } | 62 | } |
60 | 63 | ||
64 | [[nodiscard]] | ||
61 | lua_State* newState() const | 65 | lua_State* newState() const |
62 | { | 66 | { |
63 | return lua_newstate(allocF, allocUD); | 67 | return lua_newstate(allocF, allocUD); |
64 | } | 68 | } |
65 | 69 | ||
70 | [[nodiscard]] | ||
66 | void* alloc(size_t const nsize_) | 71 | void* alloc(size_t const nsize_) |
67 | { | 72 | { |
68 | return allocF(allocUD, nullptr, 0, nsize_); | 73 | return allocF(allocUD, nullptr, 0, nsize_); |
69 | } | 74 | } |
70 | 75 | ||
76 | [[nodiscard]] | ||
71 | void* alloc(void* const ptr_, size_t const osize_, size_t const nsize_) | 77 | void* alloc(void* const ptr_, size_t const osize_, size_t const nsize_) |
72 | { | 78 | { |
73 | return allocF(allocUD, ptr_, osize_, nsize_); | 79 | return allocF(allocUD, ptr_, osize_, nsize_); |