diff --git a/components/lua/utf8.cpp b/components/lua/utf8.cpp index 83228afa65..45e05b45d3 100644 --- a/components/lua/utf8.cpp +++ b/components/lua/utf8.cpp @@ -110,18 +110,19 @@ namespace LuaUtf8 }; utf8["codes"] = [](std::string_view s) { - std::vector pos_byte{ 1 }; - return sol::as_function([s, pos_byte]() mutable -> sol::optional> { - if (pos_byte.back() <= static_cast(s.size())) - { - const auto pair = decodeNextUTF8Character(s, pos_byte); - if (pair.second == -1) - throw std::runtime_error("Invalid UTF-8 code at position " + std::to_string(pos_byte.size())); - - return pair; - } - return sol::nullopt; - }); + return sol::as_function( + [s, pos_byte = std::vector{ 1 }]() mutable -> sol::optional> { + if (pos_byte.back() <= static_cast(s.size())) + { + const auto pair = decodeNextUTF8Character(s, pos_byte); + if (pair.second == -1) + throw std::runtime_error( + "Invalid UTF-8 code at position " + std::to_string(pos_byte.size())); + + return pair; + } + return sol::nullopt; + }); }; utf8["len"] = [](std::string_view s,