mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
pikalib-sysobj is ok
This commit is contained in:
parent
1bc1a44cd4
commit
4030b695b4
1
init.sh
1
init.sh
@ -8,6 +8,7 @@ git checkout master
|
||||
cd $ROOT
|
||||
rm build -rf
|
||||
mkdir build
|
||||
sh api-make.sh
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Debug ..
|
||||
cd $ROOT
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* banchmark for memory */
|
||||
#include "BaseObj.h"
|
||||
#include "SysObj.h"
|
||||
#include "PikaStdLib_SysObj.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void checker_printMem(char *info, uint32_t size)
|
||||
@ -68,7 +68,7 @@ int32_t main()
|
||||
{
|
||||
checker_objMemChecker(New_TinyObj, "tiny");
|
||||
checker_objMemChecker(New_BaseObj, "base");
|
||||
checker_objMemChecker(New_SysObj, "sys");
|
||||
checker_objMemChecker(New_PikaStdLib_SysObj, "sys");
|
||||
{
|
||||
Arg *arg = New_arg(NULL);
|
||||
checker_printMemUsage("void arg");
|
||||
|
@ -1,6 +1,5 @@
|
||||
/* this demo shows the usage of method */
|
||||
|
||||
#include "SysObj.h"
|
||||
#include "PikaStdLib_SysObj.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void obj_runWithInfo(PikaObj *self, char *cmd)
|
||||
@ -13,23 +12,23 @@ void obj_runWithInfo(PikaObj *self, char *cmd)
|
||||
int main()
|
||||
{
|
||||
/* new root object */
|
||||
PikaObj *root = newRootObj("root", New_SysObj);
|
||||
PikaObj *root = newRootObj("root", New_PikaStdLib_SysObj);
|
||||
|
||||
obj_runWithInfo(root, "set('a',1)");
|
||||
obj_runWithInfo(root, "print(a)");
|
||||
obj_runWithInfo(root, "type('a')");
|
||||
obj_runWithInfo(root, "del('a')");
|
||||
obj_runWithInfo(root, "remove('a')");
|
||||
|
||||
obj_runWithInfo(root, "set('a','test')");
|
||||
obj_runWithInfo(root, "print(a)");
|
||||
obj_runWithInfo(root, "type('a')");
|
||||
obj_runWithInfo(root, "del('a')");
|
||||
obj_runWithInfo(root, "remove('a')");
|
||||
|
||||
obj_runWithInfo(root, "set('a',1)");
|
||||
obj_runWithInfo(root, "set('b',a)");
|
||||
obj_runWithInfo(root, "print(b)");
|
||||
obj_runWithInfo(root, "del('a')");
|
||||
obj_runWithInfo(root, "del('b')");
|
||||
obj_runWithInfo(root, "remove('a')");
|
||||
obj_runWithInfo(root, "remove('b')");
|
||||
|
||||
printf("memory used max = %0.2f kB\r\n", pikaMemMax() / 1024.0);
|
||||
printf("memory used now = %0.2f kB\r\n", pikaMemNow() / 1024.0);
|
||||
|
@ -4,4 +4,6 @@ set(BINARY ${CMAKE_PROJECT_NAME})
|
||||
file(GLOB_RECURSE SOURCES LIST_DIRECTORIES true *.h *.c)
|
||||
set(SOURCES ${SOURCES})
|
||||
|
||||
add_library(${BINARY}-core STATIC ${SOURCES})
|
||||
add_library(${BINARY}-core
|
||||
STATIC
|
||||
${SOURCES})
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 5b5a363ef2aa5cac0069008b1559cf19cfee0289
|
||||
Subproject commit d65a013ec80bbbb4f708762097845dcbd2e129dd
|
@ -41,7 +41,7 @@ void PikaStdLib_SysObj_ls(PikaObj *self, char *objPath)
|
||||
/* no input obj path, use current obj */
|
||||
args_foreach(self->attributeList, __foreach_listEachArg, args);
|
||||
obj_setSysOut(self, args_getStr(args, "stringOut"));
|
||||
return;
|
||||
goto exit;
|
||||
}
|
||||
PikaObj *obj = obj_getObj(self, objPath, 0);
|
||||
if (NULL == obj)
|
||||
@ -49,12 +49,13 @@ void PikaStdLib_SysObj_ls(PikaObj *self, char *objPath)
|
||||
/* do not find obj */
|
||||
obj_setSysOut(self, "[error] list: object no found.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return;
|
||||
goto exit;
|
||||
}
|
||||
/* list args */
|
||||
args_foreach(obj->attributeList, __foreach_listEachArg, args);
|
||||
obj_setSysOut(self, args_getStr(args, "stringOut"));
|
||||
return;
|
||||
exit:
|
||||
args_deinit(args);
|
||||
}
|
||||
|
||||
void PikaStdLib_SysObj_new(PikaObj *self, char *classPath, char *objPath)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "gtest/gtest.h"
|
||||
extern "C"
|
||||
{
|
||||
#include "SysObj.h"
|
||||
#include "PikaStdLib_SysObj.h"
|
||||
#include "TinyObj.h"
|
||||
#include "BaseObj.h"
|
||||
}
|
||||
@ -52,7 +52,7 @@ void add(PikaObj *obj, Args *args)
|
||||
|
||||
PikaObj *New_PikaObj_test(Args *args)
|
||||
{
|
||||
PikaObj *self = New_SysObj(args);
|
||||
PikaObj *self = New_PikaStdLib_SysObj(args);
|
||||
class_defineMethod(self, (char *)"hello(name:str, isShow:int)", hello);
|
||||
class_defineMethod(self, (char *)"hello2(name1:str, name2:str, name3:str, isShow:int)", hello2);
|
||||
class_defineMethod(self, (char *)"testFloat(val1:float, val2:float, isShow:int)->float", testFloat);
|
||||
@ -100,7 +100,7 @@ PikaObj *New_MYROOT1(Args *args)
|
||||
|
||||
TEST(object_test, test1)
|
||||
{
|
||||
PikaObj *process = newRootObj((char *)"sys", New_SysObj);
|
||||
PikaObj *process = newRootObj((char *)"sys", New_PikaStdLib_SysObj);
|
||||
float floatTest = 12.231;
|
||||
obj_bindFloat(process, (char *)"testFloatBind", &floatTest);
|
||||
EXPECT_TRUE(strEqu((char *)"12.231000", obj_print(process, (char *)"testFloatBind")));
|
||||
@ -163,7 +163,7 @@ TEST(object_test, test6)
|
||||
|
||||
TEST(object_test, test7)
|
||||
{
|
||||
PikaObj *sys = newRootObj((char *)"sys", New_SysObj);
|
||||
PikaObj *sys = newRootObj((char *)"sys", New_PikaStdLib_SysObj);
|
||||
int32_t a = 0;
|
||||
obj_bind(sys, (char *)"int", (char *)"a", &a);
|
||||
obj_run(sys, (char *)"set('a', 1)");
|
||||
@ -174,16 +174,16 @@ TEST(object_test, test7)
|
||||
|
||||
TEST(object_test, test8)
|
||||
{
|
||||
PikaObj *sys = newRootObj((char *)"sys", New_SysObj);
|
||||
PikaObj *sys = newRootObj((char *)"sys", New_PikaStdLib_SysObj);
|
||||
obj_run(sys, (char *)"set('a', 1)");
|
||||
obj_run(sys, (char *)"del('a')");
|
||||
obj_run(sys, (char *)"remove('a')");
|
||||
obj_deinit(sys);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(object_test, test9)
|
||||
{
|
||||
PikaObj *sys = newRootObj((char *)"sys", New_SysObj);
|
||||
PikaObj *sys = newRootObj((char *)"sys", New_PikaStdLib_SysObj);
|
||||
obj_run(sys, (char *)"ls()");
|
||||
obj_setPtr(sys, (char *)"baseClass", (void *)New_TinyObj);
|
||||
obj_run(sys, (char *)"ls()");
|
||||
|
@ -1,13 +1,13 @@
|
||||
#include "gtest/gtest.h"
|
||||
extern "C"
|
||||
{
|
||||
#include "SysObj.h"
|
||||
#include "PikaStdLib_SysObj.h"
|
||||
#include "TinyObj.h"
|
||||
#include "BaseObj.h"
|
||||
}
|
||||
TEST(sysObj, print)
|
||||
{
|
||||
PikaObj *obj = newRootObj((char *)"test", New_SysObj);
|
||||
PikaObj *obj = newRootObj((char *)"test", New_PikaStdLib_SysObj);
|
||||
Args *res = obj_runDirect(obj, (char *)"print('hello world')");
|
||||
char *sysOut = args_getSysOut(res);
|
||||
int errCode = args_getErrorCode(res);
|
||||
@ -21,7 +21,7 @@ TEST(sysObj, print)
|
||||
|
||||
TEST(sysObj, set)
|
||||
{
|
||||
PikaObj *obj = newRootObj((char *)"test", New_SysObj);
|
||||
PikaObj *obj = newRootObj((char *)"test", New_PikaStdLib_SysObj);
|
||||
Args *res = obj_runDirect(obj, (char *)"set('a', 1)");
|
||||
int a = obj_getInt(obj, (char *)"a");
|
||||
char *sysOut = args_getSysOut(res);
|
||||
@ -37,7 +37,7 @@ TEST(sysObj, set)
|
||||
|
||||
TEST(sysObj, noMethod)
|
||||
{
|
||||
PikaObj *obj = newRootObj((char *)"test", New_SysObj);
|
||||
PikaObj *obj = newRootObj((char *)"test", New_PikaStdLib_SysObj);
|
||||
Args *res = obj_runDirect(obj, (char *)"printttt('hello world')");
|
||||
char *sysOut = args_getSysOut(res);
|
||||
int errCode = args_getErrorCode(res);
|
||||
|
Loading…
x
Reference in New Issue
Block a user