add PikaStdData

This commit is contained in:
lyon 2021-12-13 21:32:45 +08:00
parent 16796cb437
commit 74426e4bd3
2 changed files with 52 additions and 0 deletions

View 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

View 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);
}