From 46f519bdb8688763d1080bdc7255042cbd763430 Mon Sep 17 00:00:00 2001 From: pmp-p Date: Fri, 22 Dec 2023 09:32:10 +0100 Subject: [PATCH] add FileIO.seek internal to seek in current file, returns True on success --- src/io.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/io.cpp b/src/io.cpp index b5cb9432..172f6815 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -67,6 +67,14 @@ unsigned char* _default_import_handler(const char* name_p, int name_size, int* o return VAR(std::move(b)); }); + vm->bind_method<1>(type, "seek", [](VM* vm, ArgsView args){ + FileIO& io = CAST(FileIO&, args[0]); + size_t newpos = CAST(size_t, args[1]); + if (!fseek(io.fp, newpos, SEEK_SET)) + return vm->True; + return vm->False; + }); + vm->bind_method<1>(type, "write", [](VM* vm, ArgsView args){ FileIO& io = CAST(FileIO&, args[0]); if(io.is_text()){ @@ -203,4 +211,4 @@ void add_module_os(VM* vm){ #endif } -} // namespace pkpy \ No newline at end of file +} // namespace pkpy