|
|
@ -96,7 +96,7 @@ namespace LuaUtf8
|
|
|
|
|
|
|
|
|
|
|
|
utf8["char"] = [](const sol::variadic_args args) -> std::string {
|
|
|
|
utf8["char"] = [](const sol::variadic_args args) -> std::string {
|
|
|
|
std::string result{};
|
|
|
|
std::string result{};
|
|
|
|
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
|
|
|
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
|
|
|
|
for (size_t i = 0; i < args.size(); ++i)
|
|
|
|
for (size_t i = 0; i < args.size(); ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int64_t codepoint = getInteger(args[i], (i + 1), "char");
|
|
|
|
int64_t codepoint = getInteger(args[i], (i + 1), "char");
|
|
|
@ -104,8 +104,7 @@ namespace LuaUtf8
|
|
|
|
throw std::runtime_error(
|
|
|
|
throw std::runtime_error(
|
|
|
|
"bad argument #" + std::to_string(i + 1) + " to 'char' (value out of range)");
|
|
|
|
"bad argument #" + std::to_string(i + 1) + " to 'char' (value out of range)");
|
|
|
|
|
|
|
|
|
|
|
|
// this feels dodgy if wchar_t is 16-bit as MAXUTF won't fit in sixteen bits
|
|
|
|
result += converter.to_bytes(static_cast<char32_t>(codepoint));
|
|
|
|
result += converter.to_bytes(static_cast<wchar_t>(codepoint));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
};
|
|
|
|