mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add PikaStdData
This commit is contained in:
parent
16796cb437
commit
74426e4bd3
17
package/PikaStdData/PikaStdData.py
Normal file
17
package/PikaStdData/PikaStdData.py
Normal file
@ -0,0 +1,17 @@
|
||||
from PikaObj import *
|
||||
|
||||
class List(TinyObj):
|
||||
def init():
|
||||
pass
|
||||
|
||||
def append(arg: any):
|
||||
pass
|
||||
|
||||
def get(i: int) -> any:
|
||||
pass
|
||||
|
||||
def set(i: int, arg: any):
|
||||
pass
|
||||
|
||||
def len() -> int:
|
||||
pass
|
35
package/PikaStdData/PikaStdData_List.c
Normal file
35
package/PikaStdData/PikaStdData_List.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include "PikaStdData_List.h"
|
||||
|
||||
void PikaStdData_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 PikaStdData_List_len(PikaObj* self) {
|
||||
return obj_getInt(self, "top");
|
||||
}
|
||||
|
||||
Arg* PikaStdData_List_get(PikaObj* self, int i) {
|
||||
char buff[11];
|
||||
char* index = fast_itoa(buff, i);
|
||||
return arg_copy(obj_getArg(self, index));
|
||||
}
|
||||
void PikaStdData_List___init__(PikaObj* self) {
|
||||
/* set top index for append */
|
||||
obj_setInt(self, "top", 0);
|
||||
}
|
||||
|
||||
void PikaStdData_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