mirror of
https://github.com/luanti-org/luanti.git
synced 2025-11-18 23:55:26 +01:00
Implement core.path_exists() (#16647)
This commit is contained in:
@@ -5962,7 +5962,8 @@ Utilities
|
|||||||
touch_controls = false,
|
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.
|
* `core.mkdir(path)`: returns success.
|
||||||
* Creates a directory specified by `path`, creating parent directories
|
* Creates a directory specified by `path`, creating parent directories
|
||||||
if they don't exist.
|
if they don't exist.
|
||||||
|
|||||||
@@ -263,6 +263,21 @@ int ModApiUtil::l_is_yes(lua_State *L)
|
|||||||
return 1;
|
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()
|
// get_builtin_path()
|
||||||
int ModApiUtil::l_get_builtin_path(lua_State *L)
|
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(is_yes);
|
||||||
|
|
||||||
|
API_FCT(path_exists);
|
||||||
|
|
||||||
API_FCT(get_builtin_path);
|
API_FCT(get_builtin_path);
|
||||||
API_FCT(get_user_path);
|
API_FCT(get_user_path);
|
||||||
|
|
||||||
@@ -809,6 +826,8 @@ void ModApiUtil::InitializeAsync(lua_State *L, int top)
|
|||||||
|
|
||||||
API_FCT(is_yes);
|
API_FCT(is_yes);
|
||||||
|
|
||||||
|
API_FCT(path_exists);
|
||||||
|
|
||||||
API_FCT(get_builtin_path);
|
API_FCT(get_builtin_path);
|
||||||
API_FCT(get_user_path);
|
API_FCT(get_user_path);
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ private:
|
|||||||
// is_yes(arg)
|
// is_yes(arg)
|
||||||
static int l_is_yes(lua_State *L);
|
static int l_is_yes(lua_State *L);
|
||||||
|
|
||||||
|
// path_exists(path)
|
||||||
|
static int l_path_exists(lua_State *L);
|
||||||
|
|
||||||
// get_builtin_path()
|
// get_builtin_path()
|
||||||
static int l_get_builtin_path(lua_State *L);
|
static int l_get_builtin_path(lua_State *L);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user