forked from multitheftauto/mtasa-blue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f99707c
commit 409818a
Showing
8 changed files
with
273 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: Shared/mods/deathmatch/logic/luadefs/CLuaFileDefs.cpp | ||
* | ||
* Multi Theft Auto is available from http://www.multitheftauto.com/ | ||
* | ||
*****************************************************************************/ | ||
|
||
#include "StdInc.h" | ||
|
||
#ifndef MTA_CLIENT | ||
// NOTE: Must be included before ILuaModuleManager.h which defines its own CChecksum type. | ||
#include "CChecksum.h" | ||
#endif | ||
|
||
#include "CLuaPathDefs.h" | ||
#include "CScriptFile.h" | ||
#include "CScriptArgReader.h" | ||
#include <lua/CLuaFunctionParser.h> | ||
|
||
void CLuaPathDefs::LoadFunctions() | ||
{ | ||
constexpr static const std::pair<const char*, lua_CFunction> functions[]{ | ||
{"pathListDir", ArgumentParser<pathListDir>}, | ||
{"pathIsFile", ArgumentParser<pathIsFile>}, | ||
{"pathIsDirectory", ArgumentParser<pathIsDirectory>}, | ||
}; | ||
|
||
// Add functions | ||
for (const auto& [name, func] : functions) | ||
CLuaCFunctions::AddFunction(name, func); | ||
} | ||
|
||
void CLuaPathDefs::AddClass(lua_State* luaVM) | ||
{ | ||
lua_newclass(luaVM); | ||
|
||
lua_classfunction(luaVM, "listDir", "pathListDir"); | ||
lua_classfunction(luaVM, "isFile", "pathIsFile"); | ||
lua_classfunction(luaVM, "isDirectory", "pathIsDirectory"); | ||
|
||
lua_registerclass(luaVM, "path"); | ||
} | ||
|
||
std::optional<std::vector<std::string>> CLuaPathDefs::pathListDir( | ||
lua_State* luaVM, | ||
std::string path | ||
) { | ||
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM); | ||
if (!pLuaMain) | ||
return std::nullopt; | ||
|
||
std::string strAbsPath; | ||
|
||
CResource* pResource = pLuaMain->GetResource(); | ||
if (!CResourceManager::ParseResourcePathInput(path, pResource, &strAbsPath)) | ||
{ | ||
m_pScriptDebugging->LogWarning(luaVM, "Cannot parse provided path: \"%s\"", | ||
path.c_str()); | ||
return std::nullopt; | ||
} | ||
|
||
if (!DirectoryExists(strAbsPath)) | ||
{ | ||
m_pScriptDebugging->LogWarning(luaVM, "Directory \"%s\" doesn't exist!", | ||
path.c_str()); | ||
return std::nullopt; | ||
} | ||
|
||
return SharedUtil::ListDir(strAbsPath.c_str()); | ||
} | ||
|
||
bool CLuaPathDefs::pathIsFile(lua_State* luaVM, std::string path) | ||
{ | ||
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM); | ||
if (!pLuaMain) | ||
return false; | ||
|
||
std::string strAbsPath; | ||
|
||
CResource* pResource = pLuaMain->GetResource(); | ||
if (!CResourceManager::ParseResourcePathInput(path, pResource, &strAbsPath)) | ||
{ | ||
m_pScriptDebugging->LogWarning(luaVM, "Cannot parse provided path: \"%s\"", | ||
path.c_str()); | ||
return false; | ||
} | ||
|
||
return SharedUtil::FileExists(strAbsPath); | ||
} | ||
|
||
bool CLuaPathDefs::pathIsDirectory(lua_State* luaVM, std::string path) | ||
{ | ||
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM); | ||
if (!pLuaMain) | ||
return false; | ||
|
||
std::string strAbsPath; | ||
|
||
CResource* pResource = pLuaMain->GetResource(); | ||
if (!CResourceManager::ParseResourcePathInput(path, pResource, &strAbsPath)) | ||
{ | ||
m_pScriptDebugging->LogWarning(luaVM, "Cannot parse provided path: \"%s\"", | ||
path.c_str()); | ||
return false; | ||
} | ||
|
||
return SharedUtil::DirectoryExists(strAbsPath.c_str()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: Shared/mods/deathmatch/logic/luadefs/CLuaFileDefs.h | ||
* | ||
* Multi Theft Auto is available from http://www.multitheftauto.com/ | ||
* | ||
*****************************************************************************/ | ||
|
||
#pragma once | ||
#include "luadefs/CLuaDefs.h" | ||
|
||
class CLuaPathDefs : public CLuaDefs | ||
{ | ||
public: | ||
static void LoadFunctions(); | ||
static void AddClass(lua_State* luaVM); | ||
|
||
private: | ||
static std::optional<std::vector<std::string>> pathListDir(lua_State* luaVM, std::string path); | ||
|
||
static bool pathIsFile(lua_State* luaVM, std::string path); | ||
static bool pathIsDirectory(lua_State* luaVM, std::string path); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.