mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
support hasattr()
, proxy test ok
This commit is contained in:
parent
425640eee5
commit
74a51cd053
@ -78,7 +78,7 @@ class Dict:
|
||||
def __len__(self) -> int: ...
|
||||
|
||||
def __contains__(self, val: any) -> int:
|
||||
""" support val in list """
|
||||
""" support val in dict """
|
||||
|
||||
|
||||
class dict_keys:
|
||||
|
@ -105,14 +105,18 @@ class SysObj:
|
||||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
def hasattr(obj: object, name: str) -> int: ...
|
||||
|
||||
@ staticmethod
|
||||
@ PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
def exit(): ...
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("0")
|
||||
@ PIKA_C_MACRO_IF("0")
|
||||
class RangeObj:
|
||||
def __next__(self) -> any: ...
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("0")
|
||||
@ PIKA_C_MACRO_IF("0")
|
||||
class StringObj:
|
||||
def __next__(self) -> any: ...
|
||||
|
@ -584,3 +584,12 @@ exit:
|
||||
void PikaStdLib_SysObj_exit(PikaObj* self) {
|
||||
pks_vm_exit();
|
||||
}
|
||||
|
||||
int PikaStdLib_SysObj_hasattr(PikaObj* self, PikaObj* obj, char* name) {
|
||||
if (NULL == obj) {
|
||||
obj_setErrorCode(self, 1);
|
||||
__platform_printf("[Error] hasattr: obj is null.\r\n");
|
||||
return 0;
|
||||
}
|
||||
return obj_isArgExist(obj, name);
|
||||
}
|
||||
|
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||
"args": [
|
||||
// "--gtest_filter=vm.getattribute"
|
||||
"--gtest_filter=proxy.test1"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -78,7 +78,7 @@ class Dict:
|
||||
def __len__(self) -> int: ...
|
||||
|
||||
def __contains__(self, val: any) -> int:
|
||||
""" support val in list """
|
||||
""" support val in dict """
|
||||
|
||||
|
||||
class dict_keys:
|
||||
|
@ -105,14 +105,18 @@ class SysObj:
|
||||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
def hasattr(obj: object, name: str) -> int: ...
|
||||
|
||||
@ staticmethod
|
||||
@ PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
def exit(): ...
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("0")
|
||||
@ PIKA_C_MACRO_IF("0")
|
||||
class RangeObj:
|
||||
def __next__(self) -> any: ...
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("0")
|
||||
@ PIKA_C_MACRO_IF("0")
|
||||
class StringObj:
|
||||
def __next__(self) -> any: ...
|
||||
|
@ -584,3 +584,12 @@ exit:
|
||||
void PikaStdLib_SysObj_exit(PikaObj* self) {
|
||||
pks_vm_exit();
|
||||
}
|
||||
|
||||
int PikaStdLib_SysObj_hasattr(PikaObj* self, PikaObj* obj, char* name) {
|
||||
if (NULL == obj) {
|
||||
obj_setErrorCode(self, 1);
|
||||
__platform_printf("[Error] hasattr: obj is null.\r\n");
|
||||
return 0;
|
||||
}
|
||||
return obj_isArgExist(obj, name);
|
||||
}
|
||||
|
@ -1881,4 +1881,24 @@ TEST(vm, c_module_get_set_attr) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(vm, class_attr_ref) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
extern unsigned char pikaModules_py_a[];
|
||||
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
||||
/* run */
|
||||
__platform_printf("BEGIN\r\n");
|
||||
obj_run(pikaMain,
|
||||
"class test:\n"
|
||||
" a = 1\n"
|
||||
" b = a\n"
|
||||
"t = test()\n");
|
||||
/* collect */
|
||||
/* assert */
|
||||
/* deinit */
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -332,4 +332,24 @@ TEST(modbus, rtu_master) {
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
|
||||
TEST(proxy, test1) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
extern unsigned char pikaModules_py_a[];
|
||||
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
||||
/* run */
|
||||
__platform_printf("BEGIN\r\n");
|
||||
pikaVM_runSingleFile(pikaMain, "test/python/proxy/proxy1.py");
|
||||
/* collect */
|
||||
/* assert */
|
||||
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
||||
EXPECT_STREQ(log_buff[0], "set value = 20\r\n");
|
||||
/* deinit */
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
#endif
|
@ -2,4 +2,4 @@
|
||||
#define PIKA_VERSION_MINOR 11
|
||||
#define PIKA_VERSION_MICRO 2
|
||||
|
||||
#define PIKA_EDIT_TIME "2022/09/25 16:57:15"
|
||||
#define PIKA_EDIT_TIME "2022/09/26 10:13:58"
|
||||
|
Loading…
x
Reference in New Issue
Block a user