Add the folder contain the script to the lua load path, so script can easily require() other lua scripts inside that folder, or subfolders. See http://lua-users.org/wiki/PackagePath for details on the package.path syntax.
| 19 | // scripts inside that folder, or subfolders. |
| 20 | // See http://lua-users.org/wiki/PackagePath for details on the package.path syntax. |
| 21 | inline void luaAddScriptFolderToLoadPath(lua_State *lua_state, const char *file_name) |
| 22 | { |
| 23 | std::filesystem::path profile_path = std::filesystem::canonical(file_name); |
| 24 | std::string folder = profile_path.parent_path().generic_string(); |
| 25 | const std::string lua_code = "package.path = \"" + folder + "/?.lua;\" .. package.path"; |
| 26 | luaL_dostring(lua_state, lua_code.c_str()); |
| 27 | } |
| 28 | } // namespace osrm::util |
| 29 | |
| 30 | #endif // LUA_UTIL_HPP |