mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 02:59:54 +00:00
Add methods for file io.
This commit is contained in:
parent
8343c9edd1
commit
6321c30cb1
@ -49,12 +49,13 @@ struct IOFile {
|
||||
};
|
||||
|
||||
static int cfun_io_gc(void *p, size_t len);
|
||||
static Janet io_file_get(void *p, Janet);
|
||||
|
||||
JanetAbstractType cfun_io_filetype = {
|
||||
"core/file",
|
||||
cfun_io_gc,
|
||||
NULL,
|
||||
NULL,
|
||||
io_file_get,
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -307,6 +308,22 @@ static Janet cfun_io_fseek(int32_t argc, Janet *argv) {
|
||||
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[] = {
|
||||
{
|
||||
"file/open", cfun_io_fopen,
|
||||
|
Loading…
Reference in New Issue
Block a user