aboutsummaryrefslogtreecommitdiff
path: root/src/allocator.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/allocator.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/allocator.cpp b/src/allocator.cpp
new file mode 100644
index 0000000..84acde5
--- /dev/null
+++ b/src/allocator.cpp
@@ -0,0 +1,51 @@
1/*
2 * ALLOCATOR.CPP Copyright (c) 2017-2024, Benoit Germain
3 */
4
5/*
6===============================================================================
7
8Copyright (C) 2017-2024 Benoit Germain <bnt.germain@gmail.com>
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files (the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26THE SOFTWARE.
27
28===============================================================================
29*/
30
31#include "_pch.hpp"
32#include "allocator.hpp"
33
34namespace lanes
35{
36 AllocatorDefinition& AllocatorDefinition::Validated(lua_State* const L_, StackIndex const idx_)
37 {
38 lanes::AllocatorDefinition* const _def{ luaG_tofulluserdata<lanes::AllocatorDefinition>(L_, idx_) };
39 // raise an error and don't return if the full userdata at the specified index is not a valid AllocatorDefinition
40 if (!_def) {
41 raise_luaL_error(L_, "Bad config.allocator function, provided value is not a userdata");
42 }
43 if (lua_rawlen(L_, idx_) < sizeof(lanes::AllocatorDefinition)) {
44 raise_luaL_error(L_, "Bad config.allocator function, provided value is too small to contain a valid AllocatorDefinition");
45 }
46 if (_def->version != kAllocatorVersion) {
47 raise_luaL_error(L_, "Bad config.allocator function, AllocatorDefinition version mismatch");
48 }
49 return *_def;
50 }
51}