diff options
Diffstat (limited to 'src/state.cpp')
-rw-r--r-- | src/state.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/state.cpp b/src/state.cpp index ebe4097..5a1d2fb 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -319,7 +319,7 @@ void CallOnStateCreate(Universe* U_, lua_State* L_, lua_State* from_, LookupMode | |||
319 | * *NOT* called for keeper states! | 319 | * *NOT* called for keeper states! |
320 | * | 320 | * |
321 | */ | 321 | */ |
322 | lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_) | 322 | lua_State* luaG_newstate(Universe* U_, SourceState from_, std::optional<std::string_view> const& libs_) |
323 | { | 323 | { |
324 | DestState const _L{ create_state(U_, from_) }; | 324 | DestState const _L{ create_state(U_, from_) }; |
325 | 325 | ||
@@ -336,7 +336,7 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_) | |||
336 | STACK_CHECK(_L, 0); | 336 | STACK_CHECK(_L, 0); |
337 | 337 | ||
338 | // neither libs (not even 'base') nor special init func: we are done | 338 | // neither libs (not even 'base') nor special init func: we are done |
339 | if (libs_ == nullptr && U_->onStateCreateFunc == nullptr) { | 339 | if (!libs_.has_value() && U_->onStateCreateFunc == nullptr) { |
340 | DEBUGSPEW_CODE(DebugSpew(U_) << "luaG_newstate(nullptr)" << std::endl); | 340 | DEBUGSPEW_CODE(DebugSpew(U_) << "luaG_newstate(nullptr)" << std::endl); |
341 | return _L; | 341 | return _L; |
342 | } | 342 | } |
@@ -351,15 +351,16 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_) | |||
351 | lua_gc(_L, LUA_GCSTOP, 0); | 351 | lua_gc(_L, LUA_GCSTOP, 0); |
352 | 352 | ||
353 | // Anything causes 'base' and 'jit' to be taken in | 353 | // Anything causes 'base' and 'jit' to be taken in |
354 | if (libs_ != nullptr) { | 354 | std::string_view _libs{ libs_.value() }; |
355 | if (libs_.has_value()) { | ||
355 | // special "*" case (mainly to help with LuaJIT compatibility) | 356 | // special "*" case (mainly to help with LuaJIT compatibility) |
356 | // as we are called from luaopen_lanes_core() already, and that would deadlock | 357 | // as we are called from luaopen_lanes_core() already, and that would deadlock |
357 | if (libs_[0] == '*' && libs_[1] == 0) { | 358 | if (_libs == "*") { |
358 | DEBUGSPEW_CODE(DebugSpew(U_) << "opening ALL standard libraries" << std::endl); | 359 | DEBUGSPEW_CODE(DebugSpew(U_) << "opening ALL standard libraries" << std::endl); |
359 | luaL_openlibs(_L); | 360 | luaL_openlibs(_L); |
360 | // don't forget lanes.core for regular lane states | 361 | // don't forget lanes.core for regular lane states |
361 | open1lib(_L, kLanesCoreLibName); | 362 | open1lib(_L, kLanesCoreLibName); |
362 | libs_ = nullptr; // done with libs | 363 | _libs = ""; // done with libs |
363 | } else { | 364 | } else { |
364 | if constexpr (LUAJIT_FLAVOR() != 0) { // building against LuaJIT headers, always open jit | 365 | if constexpr (LUAJIT_FLAVOR() != 0) { // building against LuaJIT headers, always open jit |
365 | DEBUGSPEW_CODE(DebugSpew(U_) << "opening 'jit' library" << std::endl); | 366 | DEBUGSPEW_CODE(DebugSpew(U_) << "opening 'jit' library" << std::endl); |
@@ -380,9 +381,9 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_) | |||
380 | STACK_CHECK(_L, 0); | 381 | STACK_CHECK(_L, 0); |
381 | 382 | ||
382 | // scan all libraries, open them one by one | 383 | // scan all libraries, open them one by one |
383 | if (libs_) { | 384 | if (!_libs.empty()) { |
384 | unsigned int _len{ 0 }; | 385 | unsigned int _len{ 0 }; |
385 | for (char const* _p{ libs_ }; *_p; _p += _len) { | 386 | for (char const* _p{ _libs.data() }; *_p; _p += _len) { |
386 | // skip delimiters ('.' can be part of name for "lanes.core") | 387 | // skip delimiters ('.' can be part of name for "lanes.core") |
387 | while (*_p && !isalnum(*_p) && *_p != '.') | 388 | while (*_p && !isalnum(*_p) && *_p != '.') |
388 | ++_p; | 389 | ++_p; |