mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
b02672b130
* update pre-compiler * test passed for variable pars of print() * variable pars is tested ok for print() * skip arg_num check for variable * support *val in the preCompiler * add file * Merge branch 'dev' of https://gitee.com/lyon1998/pikascript into dev * fix warning * both update ByteCodeGen * use super instead of parent * create PikaList C list struct * use args inner the PikaStdData.List() * use PikaDict in PikaStdData.Dict() * support dict in c * support dict in c * clean Tinyobj
55 lines
1.5 KiB
C
55 lines
1.5 KiB
C
#include "BaseObj.h"
|
|
#include "PikaObj.h"
|
|
#include "PikaStdLib_SysObj.h"
|
|
|
|
Arg* PikaStdData_Dict_get(PikaObj* self, char* key) {
|
|
PikaDict* dict = obj_getPtr(self, "dict");
|
|
return arg_copy(dict_getArg(dict, key));
|
|
}
|
|
|
|
void PikaStdData_Dict___init__(PikaObj* self) {
|
|
PikaDict* dict = New_dict();
|
|
obj_setPtr(self, "dict", dict);
|
|
}
|
|
|
|
void PikaStdData_Dict_set(PikaObj* self, Arg* arg, char* key) {
|
|
PikaDict* dict = obj_getPtr(self, "dict");
|
|
arg_setName(arg, key);
|
|
dict_setArg(dict, arg_copy(arg));
|
|
}
|
|
|
|
void PikaStdData_Dict_remove(PikaObj* self, char* key) {
|
|
PikaDict* dict = obj_getPtr(self, "dict");
|
|
dict_removeArg(dict, dict_getArg(dict, key));
|
|
}
|
|
|
|
Arg* PikaStdData_Dict___iter__(PikaObj* self) {
|
|
obj_setInt(self, "__iter_i", 0);
|
|
return arg_setRef(NULL, "", self);
|
|
}
|
|
|
|
Arg* PikaStdData_Dict___next__(PikaObj* self) {
|
|
int __iter_i = args_getInt(self->list, "__iter_i");
|
|
PikaDict* dict = obj_getPtr(self, "dict");
|
|
Arg* res = arg_copy(args_getArgByidex(&dict->super, __iter_i));
|
|
if (NULL == res) {
|
|
return arg_setNull(NULL);
|
|
}
|
|
args_setInt(self->list, "__iter_i", __iter_i + 1);
|
|
return res;
|
|
}
|
|
|
|
void PikaStdData_Dict___set__(PikaObj* self) {
|
|
PikaStdData_Dict_set(self, obj_getArg(self, "__val"),
|
|
obj_getStr(self, "__key"));
|
|
}
|
|
|
|
Arg* PikaStdData_Dict___get__(PikaObj* self) {
|
|
return PikaStdData_Dict_get(self, obj_getStr(self, "__key"));
|
|
}
|
|
|
|
void PikaStdData_Dict___del__(PikaObj* self) {
|
|
PikaDict* dict = obj_getPtr(self, "dict");
|
|
dict_deinit(dict);
|
|
}
|