diff options
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 | ) |