File tree 5 files changed +38
-0
lines changed
5 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ extern void fileRealPath(WrenVM* vm);
24
24
extern void fileSize (WrenVM * vm );
25
25
extern void fileStat (WrenVM * vm );
26
26
extern void fileWriteBytes (WrenVM * vm );
27
+ extern void platformHomePath (WrenVM * vm );
27
28
extern void platformIsPosix (WrenVM * vm );
28
29
extern void platformName (WrenVM * vm );
29
30
extern void processAllArguments (WrenVM * vm );
@@ -169,6 +170,7 @@ static ModuleRegistry modules[] =
169
170
END_MODULE
170
171
MODULE (os )
171
172
CLASS (Platform )
173
+ STATIC_METHOD ("homePath" , platformHomePath )
172
174
STATIC_METHOD ("isPosix" , platformIsPosix )
173
175
STATIC_METHOD ("name" , platformName )
174
176
END_CLASS
Original file line number Diff line number Diff line change @@ -15,6 +15,33 @@ void osSetArguments(int argc, const char* argv[])
15
15
args = argv ;
16
16
}
17
17
18
+ void platformHomePath (WrenVM * vm )
19
+ {
20
+ wrenEnsureSlots (vm , 1 );
21
+
22
+ char _buffer [WREN_PATH_MAX ];
23
+ char * buffer = _buffer ;
24
+ size_t length = sizeof (_buffer );
25
+ int result = uv_os_homedir (buffer , & length );
26
+
27
+ if (result == UV_ENOBUFS )
28
+ {
29
+ buffer = (char * )malloc (length );
30
+ result = uv_os_homedir (buffer , & length );
31
+ }
32
+
33
+ if (result != 0 )
34
+ {
35
+ wrenSetSlotString (vm , 0 , "Cannot get the current user's home directory." );
36
+ wrenAbortFiber (vm , 0 );
37
+ return ;
38
+ }
39
+
40
+ wrenSetSlotString (vm , 0 , buffer );
41
+
42
+ if (buffer != _buffer ) free (buffer );
43
+ }
44
+
18
45
void platformName (WrenVM * vm )
19
46
{
20
47
wrenEnsureSlots (vm , 1 );
Original file line number Diff line number Diff line change 1
1
class Platform {
2
+ foreign static homePath
2
3
foreign static isPosix
3
4
foreign static name
4
5
Original file line number Diff line number Diff line change 3
3
4
4
static const char * osModuleSource =
5
5
" class Platform {\n "
6
+ " foreign static homePath\n "
6
7
" foreign static isPosix\n "
7
8
" foreign static name\n "
8
9
" \n "
Original file line number Diff line number Diff line change
1
+ import "io" for File, Directory
2
+ import "os" for Platform
3
+
4
+ System .print (Platform .homePath is String) // expect: true
5
+ System .print (! Platform .homePath .isEmpty) // expect: true
6
+ System .print (File .realPath (Platform .homePath ) == Platform .homePath ) // expect: true
7
+ System .print (Directory .exists (Platform .homePath )) // expect: true
You can’t perform that action at this time.
0 commit comments