Move File.stat() -> Stat.path().
Thanks, Michel!
This commit is contained in:
+56
-56
@@ -188,62 +188,6 @@ void fileSizePath(WrenVM* vm)
|
||||
uv_fs_stat(getLoop(), request, path, fileSizeCallback);
|
||||
}
|
||||
|
||||
// Called by libuv when the stat call completes.
|
||||
static void fileStatPathCallback(uv_fs_t* request)
|
||||
{
|
||||
if (handleRequestError(request)) return;
|
||||
|
||||
WrenVM* vm = getVM();
|
||||
wrenEnsureSlots(vm, 4);
|
||||
wrenSetSlotNewList(vm, 2);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_dev);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_ino);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_mode);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_nlink);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_uid);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_gid);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_rdev);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_size);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_blksize);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_blocks);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
// TODO: Include access, modification, and change times once we figure out
|
||||
// how we want to represent it.
|
||||
// time_t st_atime; /* time of last access */
|
||||
// time_t st_mtime; /* time of last modification */
|
||||
// time_t st_ctime; /* time of last status change */
|
||||
|
||||
schedulerResume(freeRequest(request), true);
|
||||
schedulerFinishResume();
|
||||
}
|
||||
|
||||
void fileStatPath(WrenVM* vm)
|
||||
{
|
||||
const char* path = wrenGetSlotString(vm, 1);
|
||||
uv_fs_t* request = createRequest(wrenGetSlotValue(vm, 2));
|
||||
uv_fs_stat(getLoop(), request, path, fileStatPathCallback);
|
||||
}
|
||||
|
||||
static void fileCloseCallback(uv_fs_t* request)
|
||||
{
|
||||
if (handleRequestError(request)) return;
|
||||
@@ -325,6 +269,62 @@ void fileSize(WrenVM* vm)
|
||||
uv_fs_fstat(getLoop(), request, fd, fileSizeCallback);
|
||||
}
|
||||
|
||||
// Called by libuv when the stat call completes.
|
||||
static void statPathCallback(uv_fs_t* request)
|
||||
{
|
||||
if (handleRequestError(request)) return;
|
||||
|
||||
WrenVM* vm = getVM();
|
||||
wrenEnsureSlots(vm, 4);
|
||||
wrenSetSlotNewList(vm, 2);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_dev);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_ino);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_mode);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_nlink);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_uid);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_gid);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_rdev);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_size);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_blksize);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotDouble(vm, 3, (double)request->statbuf.st_blocks);
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
// TODO: Include access, modification, and change times once we figure out
|
||||
// how we want to represent it.
|
||||
// time_t st_atime; /* time of last access */
|
||||
// time_t st_mtime; /* time of last modification */
|
||||
// time_t st_ctime; /* time of last status change */
|
||||
|
||||
schedulerResume(freeRequest(request), true);
|
||||
schedulerFinishResume();
|
||||
}
|
||||
|
||||
void statPath(WrenVM* vm)
|
||||
{
|
||||
const char* path = wrenGetSlotString(vm, 1);
|
||||
uv_fs_t* request = createRequest(wrenGetSlotValue(vm, 2));
|
||||
uv_fs_stat(getLoop(), request, path, statPathCallback);
|
||||
}
|
||||
|
||||
static void allocCallback(uv_handle_t* handle, size_t suggestedSize,
|
||||
uv_buf_t* buf)
|
||||
{
|
||||
|
||||
+9
-8
@@ -44,13 +44,6 @@ foreign class File {
|
||||
return Scheduler.runNextScheduled_()
|
||||
}
|
||||
|
||||
static stat(path) {
|
||||
if (!(path is String)) Fiber.abort("Path must be a string.")
|
||||
|
||||
statPath_(path, Fiber.current)
|
||||
return Stat.new_(Scheduler.runNextScheduled_())
|
||||
}
|
||||
|
||||
construct new_(fd) {}
|
||||
|
||||
close() {
|
||||
@@ -87,7 +80,6 @@ foreign class File {
|
||||
|
||||
foreign static open_(path, fiber)
|
||||
foreign static sizePath_(path, fiber)
|
||||
foreign static statPath_(path, fiber)
|
||||
|
||||
foreign close_(fiber)
|
||||
foreign readBytes_(count, start, fiber)
|
||||
@@ -99,6 +91,13 @@ class Stat {
|
||||
_fields = fields
|
||||
}
|
||||
|
||||
static path(path) {
|
||||
if (!(path is String)) Fiber.abort("Path must be a string.")
|
||||
|
||||
path_(path, Fiber.current)
|
||||
return Stat.new_(Scheduler.runNextScheduled_())
|
||||
}
|
||||
|
||||
device { _fields[0] }
|
||||
inode { _fields[1] }
|
||||
mode { _fields[2] }
|
||||
@@ -109,6 +108,8 @@ class Stat {
|
||||
size { _fields[7] }
|
||||
blockSize { _fields[8] }
|
||||
blockCount { _fields[9] }
|
||||
|
||||
foreign static path_(path, fiber)
|
||||
}
|
||||
|
||||
class Stdin {
|
||||
|
||||
@@ -46,13 +46,6 @@ static const char* ioModuleSource =
|
||||
" return Scheduler.runNextScheduled_()\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" static stat(path) {\n"
|
||||
" if (!(path is String)) Fiber.abort(\"Path must be a string.\")\n"
|
||||
"\n"
|
||||
" statPath_(path, Fiber.current)\n"
|
||||
" return Stat.new_(Scheduler.runNextScheduled_())\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" construct new_(fd) {}\n"
|
||||
"\n"
|
||||
" close() {\n"
|
||||
@@ -89,7 +82,6 @@ static const char* ioModuleSource =
|
||||
"\n"
|
||||
" foreign static open_(path, fiber)\n"
|
||||
" foreign static sizePath_(path, fiber)\n"
|
||||
" foreign static statPath_(path, fiber)\n"
|
||||
"\n"
|
||||
" foreign close_(fiber)\n"
|
||||
" foreign readBytes_(count, start, fiber)\n"
|
||||
@@ -101,6 +93,13 @@ static const char* ioModuleSource =
|
||||
" _fields = fields\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" static path(path) {\n"
|
||||
" if (!(path is String)) Fiber.abort(\"Path must be a string.\")\n"
|
||||
"\n"
|
||||
" path_(path, Fiber.current)\n"
|
||||
" return Stat.new_(Scheduler.runNextScheduled_())\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" device { _fields[0] }\n"
|
||||
" inode { _fields[1] }\n"
|
||||
" mode { _fields[2] }\n"
|
||||
@@ -111,6 +110,8 @@ static const char* ioModuleSource =
|
||||
" size { _fields[7] }\n"
|
||||
" blockSize { _fields[8] }\n"
|
||||
" blockCount { _fields[9] }\n"
|
||||
"\n"
|
||||
" foreign static path_(path, fiber)\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"class Stdin {\n"
|
||||
|
||||
Reference in New Issue
Block a user