Skip to content

Commit 688b808

Browse files
committed
io.chmod
1 parent 32eb327 commit 688b808

File tree

1 file changed

+25
-0
lines changed
  • docs/Runtime Environment

1 file changed

+25
-0
lines changed

docs/Runtime Environment/IO.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,28 @@ If this function is acting as a *getter*, it will return the current working dir
186186
local cwd = io.currentdir() -- Get cwd
187187
io.currentdir("abc/abc") -- Set a new cwd
188188
```
189+
190+
---
191+
### `io.chmod`
192+
Get or set file permissions on Unix-like systems.
193+
#### Parameters
194+
1. A string path or file stream. If this parameter is absent, this function works as an *availability check*.
195+
2. The desired mode/permissions. If this parameter is absent, this function works as a *getter*.
196+
#### Returns
197+
If this function is acting as an *availability check*, it will return a boolean.
198+
199+
If this function is acting as a *getter*, it will return an integer if used on a supporting platform and there wasn't an error `stat`ing the file.
200+
201+
```pluto
202+
io.contents("chmod-test.txt", "") -- create chmod-test.txt with no contents
203+
if mode := io.chmod("chmod-test.txt") then
204+
print("File mode: %o":format(mode))
205+
mode |= 0o111 -- +x
206+
io.chmod("chmod-test.txt", mode)
207+
print("New file mode: %o":format(mode))
208+
elseif io.chmod() then
209+
print("Failed to stat chmod-test.txt")
210+
else
211+
print("chmod is not available on this platform.")
212+
end
213+
```

0 commit comments

Comments
 (0)