diff options
Diffstat (limited to '')
-rw-r--r-- | src/allocator.cpp | 51 |
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 | |||
8 | Copyright (C) 2017-2024 Benoit Germain <bnt.germain@gmail.com> | ||
9 | |||
10 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
11 | of this software and associated documentation files (the "Software"), to deal | ||
12 | in the Software without restriction, including without limitation the rights | ||
13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
14 | copies of the Software, and to permit persons to whom the Software is | ||
15 | furnished to do so, subject to the following conditions: | ||
16 | |||
17 | The above copyright notice and this permission notice shall be included in | ||
18 | all copies or substantial portions of the Software. | ||
19 | |||
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
26 | THE SOFTWARE. | ||
27 | |||
28 | =============================================================================== | ||
29 | */ | ||
30 | |||
31 | #include "_pch.hpp" | ||
32 | #include "allocator.hpp" | ||
33 | |||
34 | namespace 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 | } | ||