aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/state.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/state.cpp b/src/state.cpp
index 322def8..aa6e6a9 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -247,21 +247,29 @@ namespace state {
247 STACK_CHECK(_L, 0); 247 STACK_CHECK(_L, 0);
248 248
249 // scan all libraries, open them one by one 249 // scan all libraries, open them one by one
250 if (!_libs.empty()) { 250 auto isLibNameChar = [](char const c_) {
251 unsigned int _len{ 0 }; 251 // '.' can be part of name for "lanes.core"
252 for (char const* _p{ _libs.data() }; *_p; _p += _len) { 252 return std::isalnum(c_) || c_ == '.' || c_ == '-' || c_ == '_';
253 // skip delimiters ('.' can be part of name for "lanes.core") 253 };
254 while (*_p && !std::isalnum(*_p) && *_p != '.') { 254 while (!_libs.empty()) {
255 ++_p; 255 // remove prefix not part of a name
256 } 256 auto _nameStart{ std::find_if(std::cbegin(_libs), std::cend(_libs), isLibNameChar) };
257 // skip name 257 if (_nameStart == _libs.end()) {
258 _len = 0; 258 break;
259 while (std::isalnum(_p[_len]) || _p[_len] == '.') { 259 }
260 ++_len; 260 auto const _prefixLen{ std::distance(_libs.begin(), _nameStart) };
261 } 261
262 // open library 262 auto const _nameEnd{ std::find_if(_nameStart, std::cend(_libs), [&isLibNameChar](char const _c) { return !isLibNameChar(_c); }) };
263 Open1Lib(_L, { _p, _len }); 263 // advance to the end of the character sequence composing the name
264 auto const _nameLen{ std::distance(_nameStart, _nameEnd) };
265 if (_nameLen == 0) {
266 break;
264 } 267 }
268 // open library
269 std::string_view const _libName{ _libs.substr(_prefixLen, _nameLen) };
270 Open1Lib(_L, _libName);
271 // advance to next item (can't do this earlier as it invalidates iterators)
272 _libs.remove_prefix(_prefixLen + _nameLen);
265 } 273 }
266 lua_gc(_L, LUA_GCRESTART, 0); 274 lua_gc(_L, LUA_GCRESTART, 0);
267 275