feat: add stat instance method to File class returning Stat object

Implement `File.stat` method that performs an asynchronous `fstat` call on the open file descriptor, returning a `Stat` object populated with file metadata (device, inode, mode, link count, user, group, size, block size, block count). Refactor the existing `statPathCallback` into a generic `statCallback` shared by both `statPath` and the new `fileStat` function. Bump `MAX_METHODS_PER_CLASS` from 11 to 12 to accommodate the new foreign method slot. Add comprehensive test coverage including successful stat retrieval and error handling when called on a closed file.
This commit is contained in:
Bob Nystrom
2016-02-21 18:18:45 +00:00
parent e87cd41c32
commit 42ba73b03b
7 changed files with 88 additions and 43 deletions
+3 -1
View File
@@ -18,6 +18,7 @@ extern void fileClose(WrenVM* vm);
extern void fileDescriptor(WrenVM* vm);
extern void fileReadBytes(WrenVM* vm);
extern void fileSize(WrenVM* vm);
extern void fileStat(WrenVM* vm);
extern void fileWriteBytes(WrenVM* vm);
extern void processAllArguments(WrenVM* vm);
extern void statPath(WrenVM* vm);
@@ -34,7 +35,7 @@ extern void timerStartTimer(WrenVM* vm);
// If you add a new method to the longest class below, make sure to bump this.
// Note that it also includes an extra slot for the sentinel value indicating
// the end of the list.
#define MAX_METHODS_PER_CLASS 11
#define MAX_METHODS_PER_CLASS 12
// The maximum number of foreign classes a single built-in module defines.
//
@@ -107,6 +108,7 @@ static ModuleRegistry modules[] =
METHOD("descriptor", fileDescriptor)
METHOD("readBytes_(_,_,_)", fileReadBytes)
METHOD("size_(_)", fileSize)
METHOD("stat_(_)", fileStat)
METHOD("writeBytes_(_,_,_)", fileWriteBytes)
END_CLASS
CLASS(Stat)