support f.read()

This commit is contained in:
pikastech 2022-11-25 17:32:10 +08:00
parent 3d3cfd4e25
commit bd9bd8b864
4 changed files with 16 additions and 4 deletions

View File

@ -155,7 +155,7 @@ class ByteArray:
class FILEIO: class FILEIO:
def init(self, path: str, mode: str) -> int: ... def init(self, path: str, mode: str) -> int: ...
def read(self, size: int) -> any: ... def read(self, *size) -> any: ...
def write(self, s: any) -> int: ... def write(self, s: any) -> int: ...
def close(self): ... def close(self): ...
def seek(self, offset: int, *fromwhere) -> int: ... def seek(self, offset: int, *fromwhere) -> int: ...

View File

@ -25,7 +25,13 @@ void PikaStdData_FILEIO_close(PikaObj* self) {
obj_setPtr(self, "_f", NULL); obj_setPtr(self, "_f", NULL);
} }
Arg* PikaStdData_FILEIO_read(PikaObj* self, int size) { Arg* PikaStdData_FILEIO_read(PikaObj* self, PikaTuple* size_) {
int size = 0;
if (pikaTuple_getSize(size_) == 0) {
size = -1;
}else{
size = pikaTuple_getInt(size_, 0);
}
if (size <= 0) { if (size <= 0) {
/* read all */ /* read all */
size = PIKA_READ_FILE_BUFF_SIZE; size = PIKA_READ_FILE_BUFF_SIZE;

View File

@ -155,7 +155,7 @@ class ByteArray:
class FILEIO: class FILEIO:
def init(self, path: str, mode: str) -> int: ... def init(self, path: str, mode: str) -> int: ...
def read(self, size: int) -> any: ... def read(self, *size) -> any: ...
def write(self, s: any) -> int: ... def write(self, s: any) -> int: ...
def close(self): ... def close(self): ...
def seek(self, offset: int, *fromwhere) -> int: ... def seek(self, offset: int, *fromwhere) -> int: ...

View File

@ -25,7 +25,13 @@ void PikaStdData_FILEIO_close(PikaObj* self) {
obj_setPtr(self, "_f", NULL); obj_setPtr(self, "_f", NULL);
} }
Arg* PikaStdData_FILEIO_read(PikaObj* self, int size) { Arg* PikaStdData_FILEIO_read(PikaObj* self, PikaTuple* size_) {
int size = 0;
if (pikaTuple_getSize(size_) == 0) {
size = -1;
}else{
size = pikaTuple_getInt(size_, 0);
}
if (size <= 0) { if (size <= 0) {
/* read all */ /* read all */
size = PIKA_READ_FILE_BUFF_SIZE; size = PIKA_READ_FILE_BUFF_SIZE;