|
| 1 | +/* this demo shows the usage of method */ |
| 2 | + |
| 3 | +#include "SysObj.h" |
| 4 | +#include <stdio.h> |
| 5 | + |
| 6 | +void obj_runWithInfo(MimiObj *self, char *cmd) |
| 7 | +{ |
| 8 | + printf(">>> %s\r\n", cmd); |
| 9 | + obj_run(self, cmd); |
| 10 | + printf("\r\n"); |
| 11 | +} |
| 12 | + |
| 13 | +extern DMEM_STATE DMEMS; |
| 14 | + |
| 15 | +int main() |
| 16 | +{ |
| 17 | + /* new root object */ |
| 18 | + MimiObj *root = newRootObj("root", New_SysObj); |
| 19 | + |
| 20 | + obj_runWithInfo(root, "set('a',1)"); |
| 21 | + obj_runWithInfo(root, "print(a)"); |
| 22 | + obj_runWithInfo(root, "type('a')"); |
| 23 | + obj_runWithInfo(root, "del('a')"); |
| 24 | + |
| 25 | + obj_runWithInfo(root, "set('a','test')"); |
| 26 | + obj_runWithInfo(root, "print(a)"); |
| 27 | + obj_runWithInfo(root, "type('a')"); |
| 28 | + obj_runWithInfo(root, "del('a')"); |
| 29 | + |
| 30 | + obj_runWithInfo(root, "set('a',1)"); |
| 31 | + obj_runWithInfo(root, "set('b',a)"); |
| 32 | + obj_runWithInfo(root, "print(b)"); |
| 33 | + obj_runWithInfo(root, "del('a')"); |
| 34 | + obj_runWithInfo(root, "del('b')"); |
| 35 | + |
| 36 | + printf("memory used max = %0.2f kB\r\n", DMEMS.maxNum*DMEM_BLOCK_SIZE/1024.0); |
| 37 | + printf("memory used now = %0.2f kB\r\n", DMEMS.blk_num*DMEM_BLOCK_SIZE/1024.0); |
| 38 | + |
| 39 | + /* user input buff */ |
| 40 | + char inputBuff[256] = {0}; |
| 41 | + /* run the script with check*/ |
| 42 | + while (1) |
| 43 | + { |
| 44 | + /* get user input */ |
| 45 | + fgets(inputBuff, sizeof(inputBuff), stdin); |
| 46 | + |
| 47 | + /* run mimiScript and get res */ |
| 48 | + Args *resArgs = obj_runDirect(root, inputBuff); |
| 49 | + |
| 50 | + /* get system output of mimiScript*/ |
| 51 | + char *sysOut = args_getStr(resArgs, "sysOut"); |
| 52 | + |
| 53 | + if (NULL != sysOut) |
| 54 | + { |
| 55 | + /* print out the system output */ |
| 56 | + printf("%s\r\n", sysOut); |
| 57 | + } |
| 58 | + |
| 59 | + /* deinit the res */ |
| 60 | + args_deinit(resArgs); |
| 61 | + } |
| 62 | +} |
0 commit comments