| 37 | } |
| 38 | |
| 39 | static std::filesystem::path packageNameToPath( |
| 40 | std::string_view packageName, const std::vector<std::filesystem::path>& searchDirs) |
| 41 | { |
| 42 | std::string path(packageName); |
| 43 | std::replace(path.begin(), path.end(), '.', '/'); |
| 44 | std::string pathWithInit = path + "/init.lua"; |
| 45 | path.append(".lua"); |
| 46 | for (const auto& base : searchDirs) |
| 47 | { |
| 48 | std::filesystem::path p1 = base / path; |
| 49 | if (std::filesystem::exists(p1)) |
| 50 | return p1; |
| 51 | std::filesystem::path p2 = base / pathWithInit; |
| 52 | if (std::filesystem::exists(p2)) |
| 53 | return p2; |
| 54 | } |
| 55 | throw std::runtime_error("module not found: " + std::string(packageName)); |
| 56 | } |
| 57 | |
| 58 | static const std::string safeFunctions[] = { "assert", "error", "ipairs", "next", "pairs", "pcall", "select", |
| 59 | "tonumber", "tostring", "type", "unpack", "xpcall", "rawequal", "rawget", "rawset", "setmetatable" }; |
no test coverage detected