mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 07:33:01 +00:00 
			
		
		
		
	Add methods for file io.
This commit is contained in:
		| @@ -49,12 +49,13 @@ struct IOFile { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| static int cfun_io_gc(void *p, size_t len); | static int cfun_io_gc(void *p, size_t len); | ||||||
|  | static Janet io_file_get(void *p, Janet); | ||||||
|  |  | ||||||
| JanetAbstractType cfun_io_filetype = { | JanetAbstractType cfun_io_filetype = { | ||||||
|     "core/file", |     "core/file", | ||||||
|     cfun_io_gc, |     cfun_io_gc, | ||||||
|     NULL, |     NULL, | ||||||
|     NULL, |     io_file_get, | ||||||
|     NULL |     NULL | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -307,6 +308,22 @@ static Janet cfun_io_fseek(int32_t argc, Janet *argv) { | |||||||
|     return argv[0]; |     return argv[0]; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static JanetMethod io_file_methods[] = { | ||||||
|  |     {"close", cfun_io_fclose}, | ||||||
|  |     {"read", cfun_io_fread}, | ||||||
|  |     {"write", cfun_io_fwrite}, | ||||||
|  |     {"flush", cfun_io_fflush}, | ||||||
|  |     {"seek", cfun_io_fseek}, | ||||||
|  |     {NULL, NULL} | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | static Janet io_file_get(void *p, Janet key) { | ||||||
|  |     (void) p; | ||||||
|  |     if (!janet_checktype(key, JANET_KEYWORD)) | ||||||
|  |         janet_panicf("expected keyword, got %v", key); | ||||||
|  |     return janet_getmethod(janet_unwrap_keyword(key), io_file_methods); | ||||||
|  | } | ||||||
|  |  | ||||||
| static const JanetReg io_cfuns[] = { | static const JanetReg io_cfuns[] = { | ||||||
|     { |     { | ||||||
|         "file/open", cfun_io_fopen, |         "file/open", cfun_io_fopen, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose