diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-29 15:05:19 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-29 15:05:19 +0200 |
commit | f125d90796a7394760e98380255117952bcb0109 (patch) | |
tree | 8a55aca136c8667112ee9484e11740d9ef126afc /src | |
parent | 4007dbf5a2262a7c4f2f26089071942dde7c3a91 (diff) | |
download | lanes-f125d90796a7394760e98380255117952bcb0109.tar.gz lanes-f125d90796a7394760e98380255117952bcb0109.tar.bz2 lanes-f125d90796a7394760e98380255117952bcb0109.zip |
Fix bad std::optional usage
Diffstat (limited to 'src')
-rw-r--r-- | src/state.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/state.cpp b/src/state.cpp index 271e3a7..b747a9f 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -91,7 +91,7 @@ namespace { | |||
91 | 91 | ||
92 | // ################################################################################################# | 92 | // ################################################################################################# |
93 | 93 | ||
94 | static void open1lib(lua_State* L_, std::string_view const& name_) | 94 | static void Open1Lib(lua_State* L_, std::string_view const& name_) |
95 | { | 95 | { |
96 | for (luaL_Reg const& _entry : local::sLibs) { | 96 | for (luaL_Reg const& _entry : local::sLibs) { |
97 | if (name_ == _entry.name) { | 97 | if (name_ == _entry.name) { |
@@ -285,20 +285,21 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, std::optional<std::str | |||
285 | lua_gc(_L, LUA_GCSTOP, 0); | 285 | lua_gc(_L, LUA_GCSTOP, 0); |
286 | 286 | ||
287 | // Anything causes 'base' and 'jit' to be taken in | 287 | // Anything causes 'base' and 'jit' to be taken in |
288 | std::string_view _libs{ libs_.value() }; | 288 | std::string_view _libs{}; |
289 | if (libs_.has_value()) { | 289 | if (libs_.has_value()) { |
290 | _libs = libs_.value(); | ||
290 | // special "*" case (mainly to help with LuaJIT compatibility) | 291 | // special "*" case (mainly to help with LuaJIT compatibility) |
291 | // as we are called from luaopen_lanes_core() already, and that would deadlock | 292 | // as we are called from luaopen_lanes_core() already, and that would deadlock |
292 | if (_libs == "*") { | 293 | if (_libs == "*") { |
293 | DEBUGSPEW_CODE(DebugSpew(U_) << "opening ALL standard libraries" << std::endl); | 294 | DEBUGSPEW_CODE(DebugSpew(U_) << "opening ALL standard libraries" << std::endl); |
294 | luaL_openlibs(_L); | 295 | luaL_openlibs(_L); |
295 | // don't forget lanes.core for regular lane states | 296 | // don't forget lanes.core for regular lane states |
296 | open1lib(_L, kLanesCoreLibName); | 297 | Open1Lib(_L, kLanesCoreLibName); |
297 | _libs = ""; // done with libs | 298 | _libs = ""; // done with libs |
298 | } else { | 299 | } else { |
299 | if constexpr (LUAJIT_FLAVOR() != 0) { // building against LuaJIT headers, always open jit | 300 | if constexpr (LUAJIT_FLAVOR() != 0) { // building against LuaJIT headers, always open jit |
300 | DEBUGSPEW_CODE(DebugSpew(U_) << "opening 'jit' library" << std::endl); | 301 | DEBUGSPEW_CODE(DebugSpew(U_) << "opening 'jit' library" << std::endl); |
301 | open1lib(_L, LUA_JITLIBNAME); | 302 | Open1Lib(_L, LUA_JITLIBNAME); |
302 | } | 303 | } |
303 | DEBUGSPEW_CODE(DebugSpew(U_) << "opening 'base' library" << std::endl); | 304 | DEBUGSPEW_CODE(DebugSpew(U_) << "opening 'base' library" << std::endl); |
304 | if constexpr (LUA_VERSION_NUM >= 502) { | 305 | if constexpr (LUA_VERSION_NUM >= 502) { |
@@ -319,14 +320,16 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, std::optional<std::str | |||
319 | unsigned int _len{ 0 }; | 320 | unsigned int _len{ 0 }; |
320 | for (char const* _p{ _libs.data() }; *_p; _p += _len) { | 321 | for (char const* _p{ _libs.data() }; *_p; _p += _len) { |
321 | // skip delimiters ('.' can be part of name for "lanes.core") | 322 | // skip delimiters ('.' can be part of name for "lanes.core") |
322 | while (*_p && !isalnum(*_p) && *_p != '.') | 323 | while (*_p && !std::isalnum(*_p) && *_p != '.') { |
323 | ++_p; | 324 | ++_p; |
325 | } | ||
324 | // skip name | 326 | // skip name |
325 | _len = 0; | 327 | _len = 0; |
326 | while (isalnum(_p[_len]) || _p[_len] == '.') | 328 | while (std::isalnum(_p[_len]) || _p[_len] == '.') { |
327 | ++_len; | 329 | ++_len; |
330 | } | ||
328 | // open library | 331 | // open library |
329 | open1lib(_L, { _p, _len }); | 332 | Open1Lib(_L, { _p, _len }); |
330 | } | 333 | } |
331 | } | 334 | } |
332 | lua_gc(_L, LUA_GCRESTART, 0); | 335 | lua_gc(_L, LUA_GCRESTART, 0); |