diff --git a/port/linux/package/pikascript/PikaStdLib.py b/port/linux/package/pikascript/PikaStdLib.py index 6c4b4dd91..378534e92 100644 --- a/port/linux/package/pikascript/PikaStdLib.py +++ b/port/linux/package/pikascript/PikaStdLib.py @@ -30,8 +30,8 @@ class List(TinyObj): def get(i: int) -> any: pass - def len() -> int: + def set(i: int, arg: any): pass - def remove(arg: any): + def len() -> int: pass diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_List.c b/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_List.c index 68145a616..be82d88c4 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_List.c +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_List.c @@ -1,16 +1,35 @@ #include "PikaStdLib_List.h" void PikaStdLib_List_append(PikaObj* self, Arg* arg) { - obj_setArg(self, "", arg); + int top = obj_getInt(self, "top"); + char buff[11]; + char* topStr = fast_itoa(buff, top); + obj_setArg(self, topStr, arg); + /* top++ */ + obj_setInt(self, "top", top + 1); } + int PikaStdLib_List_len(PikaObj* self) { - return 0; + return obj_getInt(self, "top"); } + Arg* PikaStdLib_List_get(PikaObj* self, int i) { - return NULL; + char buff[11]; + char* index = fast_itoa(buff, i); + return obj_getArg(self, index); } -void PikaStdLib_List_remove(PikaObj* self, Arg* arg) {} void PikaStdLib_List_init(PikaObj* self) { /* set top index for append */ - obj_setInt(self, "__top", 0); -} \ No newline at end of file + obj_setInt(self, "top", 0); +} + +void PikaStdLib_List_set(PikaObj* self, Arg* arg, int i) { + char buff[11]; + char* i_str = fast_itoa(buff, i); + int top = obj_getInt(self, "top"); + if (i > top) { + obj_setErrorCode(self, 1); + obj_setSysOut(self, "[error]: index exceeded lengh of list."); + } + obj_setArg(self, i_str, arg); +}