mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add obj/args_setNone() api
This commit is contained in:
parent
23fd342008
commit
b4a79e00dd
@ -180,6 +180,7 @@ PIKA_RES obj_setFloat(PikaObj* self, char* argPath, pika_float value) {
|
||||
}
|
||||
|
||||
PIKA_RES obj_setStr(PikaObj* self, char* argPath, char* str) {
|
||||
pika_assert(NULL != str);
|
||||
PikaObj* obj = obj_getHostObj(self, argPath);
|
||||
if (NULL == obj) {
|
||||
return PIKA_RES_ERR_ARG_NO_FOUND;
|
||||
@ -189,6 +190,16 @@ PIKA_RES obj_setStr(PikaObj* self, char* argPath, char* str) {
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
|
||||
PIKA_RES obj_setNone(PikaObj* self, char* argPath) {
|
||||
PikaObj* obj = obj_getHostObj(self, argPath);
|
||||
if (NULL == obj) {
|
||||
return PIKA_RES_ERR_ARG_NO_FOUND;
|
||||
}
|
||||
char* name = strPointToLastToken(argPath, '.');
|
||||
args_setNone(obj->list, name);
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
|
||||
PIKA_RES obj_setBytes(PikaObj* self, char* argPath, uint8_t* src, size_t size) {
|
||||
PikaObj* obj = obj_getHostObj(self, argPath);
|
||||
if (NULL == obj) {
|
||||
|
@ -162,6 +162,7 @@ PIKA_RES obj_setRef(PikaObj* self, char* argPath, PikaObj* pointer);
|
||||
PIKA_RES obj_setPtr(PikaObj* self, char* argPath, void* pointer);
|
||||
PIKA_RES obj_setFloat(PikaObj* self, char* argPath, pika_float value);
|
||||
PIKA_RES obj_setStr(PikaObj* self, char* argPath, char* str);
|
||||
PIKA_RES obj_setNone(PikaObj* self, char* argPath);
|
||||
PIKA_RES obj_setArg(PikaObj* self, char* argPath, Arg* arg);
|
||||
PIKA_RES obj_setArg_noCopy(PikaObj* self, char* argPath, Arg* arg);
|
||||
PIKA_RES obj_setBytes(PikaObj* self, char* argPath, uint8_t* src, size_t size);
|
||||
|
@ -85,6 +85,7 @@ PIKA_RES args_setRef(Args* self, char* name, void* argPointer) {
|
||||
}
|
||||
|
||||
PIKA_RES args_setStr(Args* self, char* name, char* strIn) {
|
||||
pika_assert(NULL != strIn);
|
||||
PIKA_RES errCode = PIKA_RES_OK;
|
||||
Arg* argNew = New_arg(NULL);
|
||||
argNew = arg_setStr(argNew, name, strIn);
|
||||
@ -95,6 +96,14 @@ PIKA_RES args_setStr(Args* self, char* name, char* strIn) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
PIKA_RES args_setNone(Args* self, char* name) {
|
||||
PIKA_RES errCode = PIKA_RES_OK;
|
||||
Arg* argNew = arg_newNull();
|
||||
arg_setName(argNew, name);
|
||||
args_setArg(self, argNew);
|
||||
return errCode;
|
||||
}
|
||||
|
||||
PIKA_RES args_pushArg(Args* self, Arg* arg) {
|
||||
Arg* new_arg = NULL;
|
||||
if (!arg_isSerialized(arg)) {
|
||||
|
@ -57,6 +57,7 @@ int32_t args_isArgExist_hash(Args* self, Hash nameHash);
|
||||
int32_t args_isArgExist(Args* self, char* name);
|
||||
|
||||
PIKA_RES args_setStr(Args* self, char* name, char* strIn);
|
||||
PIKA_RES args_setNone(Args* self, char* name);
|
||||
PIKA_RES args_setStrWithDefaultName(Args* self, char* strIn);
|
||||
char* args_getStr(Args* self, char* name);
|
||||
|
||||
|
@ -2830,4 +2830,13 @@ TEST(pikaMain, REPL_key_left_del) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(pikaMain, obj_setNone) {
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
obj_setNone(pikaMain, "n");
|
||||
obj_run(pikaMain, "print(n)");
|
||||
EXPECT_STREQ(log_buff[0], "None\r\n");
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST_END
|
Loading…
x
Reference in New Issue
Block a user