aboutsummaryrefslogtreecommitdiff
path: root/src/state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/state.cpp')
-rw-r--r--src/state.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/state.cpp b/src/state.cpp
index ee0b199..bae2ba5 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -195,24 +195,27 @@ namespace state {
195 195
196 // ############################################################################################# 196 // #############################################################################################
197 197
198 lua_State* CreateState([[maybe_unused]] Universe* const U_, lua_State* const from_) 198 lua_State* CreateState([[maybe_unused]] Universe* const U_, lua_State* const from_, std::string_view const& hint_)
199 { 199 {
200 lua_State* const _L { 200 lua_State* const _L {
201 std::invoke( 201 std::invoke(
202 [U = U_, from = from_]() { 202 [U = U_, from = from_, &hint = hint_]() {
203 if constexpr (LUAJIT_FLAVOR() == 64) { 203 if constexpr (LUAJIT_FLAVOR() == 64) {
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 if (U->provideAllocator != nullptr) { // we have a function we can call to obtain an allocator
208 lua_pushcclosure(from, U->provideAllocator, 0); 208 STACK_CHECK_START_REL(from, 0);
209 lua_call(from, 0, 1); 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
210 AllocatorDefinition* const _def{ luaG_tofulluserdata<AllocatorDefinition>(from, -1) }; 212 AllocatorDefinition* const _def{ luaG_tofulluserdata<AllocatorDefinition>(from, -1) };
211 if (!_def || _def->version != AllocatorDefinition::kAllocatorVersion) { 213 if (!_def || _def->version != AllocatorDefinition::kAllocatorVersion) {
212 raise_luaL_error(from, "Bad config.allocator function, must provide a valid AllocatorDefinition"); 214 raise_luaL_error(from, "Bad config.allocator function, must provide a valid AllocatorDefinition");
213 } 215 }
214 lua_State* const _L{ lua_newstate(_def->allocF, _def->allocUD) }; 216 lua_State* const _L{ lua_newstate(_def->allocF, _def->allocUD) };
215 lua_pop(from, 1); 217 lua_pop(from, 1); // L:
218 STACK_CHECK(from, 0);
216 return _L; 219 return _L;
217 } else { 220 } else {
218 // reuse the allocator provided when the master state was created 221 // reuse the allocator provided when the master state was created
@@ -271,7 +274,7 @@ namespace state {
271 */ 274 */
272 lua_State* NewLaneState(Universe* const U_, SourceState const from_, std::optional<std::string_view> const& libs_) 275 lua_State* NewLaneState(Universe* const U_, SourceState const from_, std::optional<std::string_view> const& libs_)
273 { 276 {
274 DestState const _L{ CreateState(U_, from_) }; 277 DestState const _L{ CreateState(U_, from_, "lane") };
275 278
276 STACK_GROW(_L, 2); 279 STACK_GROW(_L, 2);
277 STACK_CHECK_START_ABS(_L, 0); 280 STACK_CHECK_START_ABS(_L, 0);