1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-18 07:35:27 +01:00

Implement core.path_exists() (#16647)

This commit is contained in:
Rising Leaf
2025-11-16 06:00:36 -08:00
committed by GitHub
parent 7e53e65549
commit 44e7c5b9ab
3 changed files with 24 additions and 1 deletions

View File

@@ -5962,7 +5962,8 @@ Utilities
touch_controls = false,
}
```
* `core.path_exists(path)`: returns true if the given path exists else false
* `path` is the path that will be tested can be either a directory or a file
* `core.mkdir(path)`: returns success.
* Creates a directory specified by `path`, creating parent directories
if they don't exist.

View File

@@ -263,6 +263,21 @@ int ModApiUtil::l_is_yes(lua_State *L)
return 1;
}
// path_exists(path)
int ModApiUtil::l_path_exists(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
std::string path = luaL_checkstring(L, 1); //path
CHECK_SECURE_PATH(L, path.c_str(), false);
bool exists = fs::PathExists(path);
lua_pushboolean(L, exists);
return 1;
}
// get_builtin_path()
int ModApiUtil::l_get_builtin_path(lua_State *L)
{
@@ -724,6 +739,8 @@ void ModApiUtil::Initialize(lua_State *L, int top)
API_FCT(is_yes);
API_FCT(path_exists);
API_FCT(get_builtin_path);
API_FCT(get_user_path);
@@ -809,6 +826,8 @@ void ModApiUtil::InitializeAsync(lua_State *L, int top)
API_FCT(is_yes);
API_FCT(path_exists);
API_FCT(get_builtin_path);
API_FCT(get_user_path);

View File

@@ -52,6 +52,9 @@ private:
// is_yes(arg)
static int l_is_yes(lua_State *L);
// path_exists(path)
static int l_path_exists(lua_State *L);
// get_builtin_path()
static int l_get_builtin_path(lua_State *L);