1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-05 00:06:16 +00:00

Merge pull request #230 from andrewchambers/file_api

Extend file api to allow creating and checking.
This commit is contained in:
Calvin Rose 2019-12-29 10:22:03 -05:00 committed by GitHub
commit a2e515ab89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -663,6 +663,20 @@ FILE *janet_getfile(const Janet *argv, int32_t n, int *flags) {
return iof->file; return iof->file;
} }
Janet janet_makefile(FILE *f, int flags) {
return makef(f, flags);
}
JanetAbstract janet_checkfile(Janet j) {
return janet_checkabstract(j, &cfun_io_filetype);
}
FILE* janet_unwrapfile(Janet j, int *flags) {
IOFile *iof = janet_unwrap_abstract(j);
if (NULL != flags) *flags = iof->flags;
return iof->file;
}
/* Module entry point */ /* Module entry point */
void janet_lib_io(JanetTable *env) { void janet_lib_io(JanetTable *env) {
janet_core_cfuns(env, NULL, io_cfuns); janet_core_cfuns(env, NULL, io_cfuns);

View File

@ -1464,8 +1464,11 @@ JANET_API void janet_setdyn(const char *name, Janet value);
#define JANET_FILE_SERIALIZABLE 128 #define JANET_FILE_SERIALIZABLE 128
#define JANET_FILE_PIPED 256 #define JANET_FILE_PIPED 256
JANET_API Janet janet_makefile(FILE *f, int flags);
JANET_API FILE *janet_getfile(const Janet *argv, int32_t n, int *flags); JANET_API FILE *janet_getfile(const Janet *argv, int32_t n, int *flags);
JANET_API FILE *janet_dynfile(const char *name, FILE *def); JANET_API FILE *janet_dynfile(const char *name, FILE *def);
JANET_API JanetAbstract janet_checkfile(Janet j);
JANET_API FILE *janet_unwrapfile(Janet j, int *flags);
/* Marshal API */ /* Marshal API */
JANET_API void janet_marshal_size(JanetMarshalContext *ctx, size_t value); JANET_API void janet_marshal_size(JanetMarshalContext *ctx, size_t value);