diff --git a/src/core/io.c b/src/core/io.c index 0a6534d4..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); @@ -416,4 +424,5 @@ 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.")); + } diff --git a/src/include/janet.h b/src/include/janet.h index 3091cc04..edffaf83 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -1254,6 +1254,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);