mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 15:26:59 +00:00
Lua: Add various FS functions
This commit is contained in:
parent
23ffa25d78
commit
fe3ccafc1d
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<std::string>()) {
|
||||
beammp_lua_error("FS.Concat called with non-string argument");
|
||||
return "";
|
||||
}
|
||||
Path += Obj.as<std::string>();
|
||||
if (i < Args.size() - 1 && !Path.empty()) {
|
||||
Path += fs::path::preferred_separator;
|
||||
}
|
||||
}
|
||||
auto Result = Path.lexically_normal().string();
|
||||
return Result;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user