From d70049dbb173ba7c16fbfa4071047ba56936ae96 Mon Sep 17 00:00:00 2001 From: "J.-F. Cap" Date: Wed, 27 Feb 2019 10:54:10 +0100 Subject: [PATCH 1/2] Register core/file abstract type --- src/core/io.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/io.c b/src/core/io.c index 0a6534d4..3540dd40 100644 --- a/src/core/io.c +++ b/src/core/io.c @@ -416,4 +416,7 @@ void janet_lib_io(JanetTable *env) { janet_core_def(env, "stdin", makef(stdin, IO_READ | IO_NOT_CLOSEABLE | IO_SERIALIZABLE), JDOC("The standard input file.")); + + janet_register_abstract_type(&cfun_io_filetype); + } From 1753f8bc189639e0c103b647a77e09c40ecca201 Mon Sep 17 00:00:00 2001 From: "J.-F. Cap" Date: Sat, 2 Mar 2019 15:36:34 +0100 Subject: [PATCH 2/2] Added janet_getfile C API function and revert core/file AT registering --- src/core/io.c | 10 ++++++++-- src/include/janet.h | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/io.c b/src/core/io.c index 3540dd40..2f89c53f 100644 --- a/src/core/io.c +++ b/src/core/io.c @@ -400,6 +400,14 @@ static const JanetReg io_cfuns[] = { {NULL, NULL, NULL} }; +/* C API */ + +FILE *janet_getfile(const Janet *argv, int32_t n, int *flags) { + IOFile *iof = janet_getabstract(argv, n, &cfun_io_filetype); + *flags = iof->flags; + return iof->file; +} + /* Module entry point */ void janet_lib_io(JanetTable *env) { janet_core_cfuns(env, NULL, io_cfuns); @@ -417,6 +425,4 @@ void janet_lib_io(JanetTable *env) { makef(stdin, IO_READ | IO_NOT_CLOSEABLE | IO_SERIALIZABLE), JDOC("The standard input file.")); - janet_register_abstract_type(&cfun_io_filetype); - } diff --git a/src/include/janet.h b/src/include/janet.h index d1e811e1..341a85cb 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -1250,6 +1250,8 @@ JANET_API JanetRange janet_getslice(int32_t argc, const Janet *argv); JANET_API int32_t janet_gethalfrange(const Janet *argv, int32_t n, int32_t length, const char *which); JANET_API int32_t janet_getargindex(const Janet *argv, int32_t n, int32_t length, const char *which); +JANET_API FILE *janet_getfile(const Janet *argv, int32_t n, int *flags); + /* Marshal API */ JANET_API void janet_marshal_int(JanetMarshalContext *ctx, int32_t value);