diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-18 14:06:07 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-18 14:06:07 +0200 |
commit | 271ce5cff2b5e9c1e4d4f236c731ceb263716681 (patch) | |
tree | f26ae0570b0442938fbe08ca4542e8ca8f92504a /src/state.cpp | |
parent | 6b6e7827362b3d56cd588a76ef9d3bd6baec52f1 (diff) | |
download | lanes-271ce5cff2b5e9c1e4d4f236c731ceb263716681.tar.gz lanes-271ce5cff2b5e9c1e4d4f236c731ceb263716681.tar.bz2 lanes-271ce5cff2b5e9c1e4d4f236c731ceb263716681.zip |
Give a chance to config.allocator to provide a specific allocator for internal stuff
Diffstat (limited to 'src/state.cpp')
-rw-r--r-- | src/state.cpp | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/src/state.cpp b/src/state.cpp index 6d3910b..1975148 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -204,23 +204,8 @@ namespace state { | |||
204 | // for some reason, LuaJIT 64 bits does not support creating a state with lua_newstate... | 204 | // for some reason, LuaJIT 64 bits does not support creating a state with lua_newstate... |
205 | return luaL_newstate(); | 205 | return luaL_newstate(); |
206 | } else { | 206 | } else { |
207 | if (U->provideAllocator != nullptr) { // we have a function we can call to obtain an allocator | 207 | lanes::AllocatorDefinition const _def{ U->resolveAllocator(from, hint) }; |
208 | STACK_CHECK_START_REL(from, 0); | 208 | return lua_newstate(_def.allocF, _def.allocUD); |
209 | lua_pushcclosure(from, U->provideAllocator, 0); // L: provideAllocator() | ||
210 | luaG_pushstring(from, hint); // L: provideAllocator() "<hint>" | ||
211 | lua_call(from, 1, 1); // L: result | ||
212 | lanes::AllocatorDefinition* const _def{ luaG_tofulluserdata<lanes::AllocatorDefinition>(from, -1) }; | ||
213 | if (!_def || _def->version != lanes::AllocatorDefinition::kAllocatorVersion) { | ||
214 | raise_luaL_error(from, "Bad config.allocator function, must provide a valid AllocatorDefinition"); | ||
215 | } | ||
216 | lua_State* const _L{ lua_newstate(_def->allocF, _def->allocUD) }; | ||
217 | lua_pop(from, 1); // L: | ||
218 | STACK_CHECK(from, 0); | ||
219 | return _L; | ||
220 | } else { | ||
221 | // reuse the allocator provided when the master state was created | ||
222 | return lua_newstate(U->protectedAllocator.allocF, U->protectedAllocator.allocUD); | ||
223 | } | ||
224 | } | 209 | } |
225 | } | 210 | } |
226 | ) | 211 | ) |