MCPcopy Create free account
hub / github.com/OpenMW/openmw / packageNameToPath

Function packageNameToPath

components/lua/luastate.cpp:39–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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" };

Callers 1

loadInternalLibMethod · 0.85

Calls 3

beginMethod · 0.45
endMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected