mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
add PikaStdLib_List class
This commit is contained in:
parent
ab7e59b47d
commit
88c00687d0
35
package/PikaStdLib/PikaStdLib_List.c
Normal file
35
package/PikaStdLib/PikaStdLib_List.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include "PikaStdLib_List.h"
|
||||
|
||||
void PikaStdLib_List_append(PikaObj* self, Arg* 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 obj_getInt(self, "top");
|
||||
}
|
||||
|
||||
Arg* PikaStdLib_List_get(PikaObj* self, int i) {
|
||||
char buff[11];
|
||||
char* index = fast_itoa(buff, i);
|
||||
return arg_copy(obj_getArg(self, index));
|
||||
}
|
||||
void PikaStdLib_List_init(PikaObj* self) {
|
||||
/* set top index for append */
|
||||
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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user