luautf8lib

macos_ci_fix
Kindi 1 year ago
parent 84e71f4977
commit 8622a6da3b

@ -34,7 +34,7 @@ endif (GIT_CHECKOUT)
# source files
add_component_dir (lua
luastate scriptscontainer asyncpackage utilpackage serialization configuration l10n storage
luastate scriptscontainer asyncpackage utilpackage serialization configuration l10n storage utf8
shapes/box
)

@ -12,6 +12,7 @@
#include <components/vfs/manager.hpp>
#include "scriptscontainer.hpp"
#include "utf8.hpp"
namespace LuaUtil
{
@ -51,7 +52,7 @@ namespace LuaUtil
static const std::string safeFunctions[] = { "assert", "error", "ipairs", "next", "pairs", "pcall", "select",
"tonumber", "tostring", "type", "unpack", "xpcall", "rawequal", "rawget", "rawset", "setmetatable" };
static const std::string safePackages[] = { "coroutine", "math", "string", "table" };
static const std::string safePackages[] = { "coroutine", "math", "string", "table", "utf8" };
static constexpr int64_t countHookStep = 1000;
@ -181,6 +182,8 @@ namespace LuaUtil
mSol["math"]["randomseed"](static_cast<unsigned>(std::time(nullptr)));
mSol["math"]["randomseed"] = [] {};
mSol["utf8"] = LuaUtf8::initUtf8Package(mSol);
mSol["writeToLog"] = [](std::string_view s) { Log(Debug::Level::Info) << s; };
mSol["setEnvironment"]

@ -0,0 +1,21 @@
#include "utf8.hpp"
#include "luastate.hpp"
namespace
{
static constexpr std::string_view UTF8PATT = "[%z\x01-\x7F\xC2-\xF4][\x80-\xBF]*"; // %z is deprecated in Lua5.2
static constexpr uint32_t MAXUTF = 0x7FFFFFFFu;
static constexpr uint32_t MAXUNICODE = 0x10FFFFu;
}
namespace LuaUtf8
{
sol::table initUtf8Package(sol::state_view& lua)
{
sol::table utf8(lua, sol::create);
utf8["charpattern"] = UTF8PATT;
return utf8;
}
}

@ -0,0 +1,9 @@
#ifndef COMPONENTS_LUA_UTF8_H
#define COMPONENTS_LUA_UTF8_H
namespace LuaUtf8
{
sol::table initUtf8Package(sol::state_view&);
}
#endif
Loading…
Cancel
Save