diff --git a/include/LuaAPI.h b/include/LuaAPI.h index 3444a1a..188cb78 100644 --- a/include/LuaAPI.h +++ b/include/LuaAPI.h @@ -32,5 +32,8 @@ namespace FS { std::string GetExtension(const std::string& Path); std::string GetParentFolder(const std::string& Path); bool Exists(const std::string& Path); + bool IsDirectory(const std::string& Path); + bool IsFile(const std::string& Path); + std::string ConcatPaths(sol::variadic_args Args); } } diff --git a/src/LuaAPI.cpp b/src/LuaAPI.cpp index a19049b..46fffe4 100644 --- a/src/LuaAPI.cpp +++ b/src/LuaAPI.cpp @@ -321,5 +321,30 @@ std::string LuaAPI::FS::GetExtension(const std::string& Path) { } std::string LuaAPI::FS::GetParentFolder(const std::string& Path) { - return fs::relative(Path).parent_path().string(); + return fs::path(Path).parent_path().string(); +} + +bool LuaAPI::FS::IsDirectory(const std::string& Path) { + return fs::is_directory(Path); +} + +bool LuaAPI::FS::IsFile(const std::string& Path) { + return fs::is_regular_file(Path); +} + +std::string LuaAPI::FS::ConcatPaths(sol::variadic_args Args) { + fs::path Path; + for (size_t i = 0; i < Args.size(); ++i) { + auto Obj = Args[i]; + if (!Obj.is()) { + beammp_lua_error("FS.Concat called with non-string argument"); + return ""; + } + Path += Obj.as(); + if (i < Args.size() - 1 && !Path.empty()) { + Path += fs::path::preferred_separator; + } + } + auto Result = Path.lexically_normal().string(); + return Result; } diff --git a/src/TLuaEngine.cpp b/src/TLuaEngine.cpp index 8b9cef1..e678f54 100644 --- a/src/TLuaEngine.cpp +++ b/src/TLuaEngine.cpp @@ -458,6 +458,9 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, std::atomi FSTable.set_function("GetFilename", &LuaAPI::FS::GetFilename); FSTable.set_function("GetExtension", &LuaAPI::FS::GetExtension); FSTable.set_function("GetParentFolder", &LuaAPI::FS::GetParentFolder); + FSTable.set_function("IsDirectory", &LuaAPI::FS::IsDirectory); + FSTable.set_function("IsFile", &LuaAPI::FS::IsFile); + FSTable.set_function("ConcatPaths", &LuaAPI::FS::ConcatPaths); Start(); }