add file.is_writeable
This commit is contained in:
parent
d55d02ac9d
commit
bc4aea67c9
@ -42,3 +42,9 @@ end
|
||||
debug.log("delete file")
|
||||
file.remove("config:binary")
|
||||
assert(not file.exists("config:binary"))
|
||||
|
||||
debug.log("checking entry points for writeability")
|
||||
assert(file.is_writeable("config:"))
|
||||
assert(file.is_writeable("export:"))
|
||||
assert(not file.is_writeable("user:"))
|
||||
assert(not file.is_writeable("res:"))
|
||||
|
||||
@ -25,6 +25,12 @@ file.read_bytes(path: str) -> array of integers
|
||||
|
||||
Read file into bytes array.
|
||||
|
||||
```lua
|
||||
file.is_writeable(path: str) -> bool
|
||||
```
|
||||
|
||||
Checks if the specified path is writable.
|
||||
|
||||
```python
|
||||
file.write(path: str, text: str) -> nil
|
||||
```
|
||||
|
||||
@ -25,6 +25,12 @@ file.read_bytes(путь: str) -> array of integers
|
||||
|
||||
Читает файл в массив байт.
|
||||
|
||||
```lua
|
||||
file.is_writeable(путь: str) -> bool
|
||||
```
|
||||
|
||||
Проверяет, доступно ли право записи по указанному пути.
|
||||
|
||||
```python
|
||||
file.write(путь: str, текст: str) -> nil
|
||||
```
|
||||
|
||||
@ -243,6 +243,16 @@ static int l_read_combined_object(lua::State* L) {
|
||||
return lua::pushvalue(L, engine->getResPaths()->readCombinedObject(path));
|
||||
}
|
||||
|
||||
static int l_is_writeable(lua::State* L) {
|
||||
std::string rawpath = lua::require_string(L, 1);
|
||||
fs::path path = resolve_path(rawpath);
|
||||
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
|
||||
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
|
||||
return lua::pushboolean(L, false);
|
||||
}
|
||||
return lua::pushboolean(L, true);
|
||||
}
|
||||
|
||||
const luaL_Reg filelib[] = {
|
||||
{"exists", lua::wrap<l_exists>},
|
||||
{"find", lua::wrap<l_find>},
|
||||
@ -263,4 +273,5 @@ const luaL_Reg filelib[] = {
|
||||
{"gzip_decompress", lua::wrap<l_gzip_decompress>},
|
||||
{"read_combined_list", lua::wrap<l_read_combined_list>},
|
||||
{"read_combined_object", lua::wrap<l_read_combined_object>},
|
||||
{"is_writeable", lua::wrap<l_is_writeable>},
|
||||
{NULL, NULL}};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user