forked from pikasTech/PikaPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPikaBlock.c
More file actions
88 lines (74 loc) · 2.15 KB
/
PikaBlock.c
File metadata and controls
88 lines (74 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "PikaBlock.h"
#include <stdarg.h>
#include "PikaObj.h"
#include "TinyObj.h"
#include "dataArgs.h"
#include "dataMemory.h"
#include "dataString.h"
#include "dataStrs.h"
void block_deinit(PikaObj* self) {
obj_deinit(self);
}
PikaObj* block_init(Args* args) {
PikaObj* self = New_TinyObj(args);
obj_setStr(self, "mode", "");
obj_setStr(self, "assert", "");
obj_setStr(self, "body", "");
obj_setInt(self, "lineSize", 0);
obj_setStr(self, "lineNow", "");
return self;
}
char* block_getBody(PikaObj* self) {
return obj_getStr(self, "body");
}
void block_setBody(PikaObj* self, char* body) {
obj_setStr(self, "body", body);
}
uint8_t block_checkAssert(PikaObj* self) {
Args* buffs = New_strBuff();
PikaObj* host = obj_getContext(self);
char* assert = block_getAssert(self);
obj_run(host, strsFormat(buffs, 32, "_res = %s", assert));
int res = obj_getInt(host, "_res");
obj_removeArg(host, "_res");
args_deinit(buffs);
return res;
}
uint16_t block_getLineSize(PikaObj* self) {
return obj_getInt(self, "lineSize");
}
void block_setAssert(PikaObj* self, char* assert) {
obj_setStr(self, "assert", assert);
}
char* block_getAssert(PikaObj* self) {
return obj_getStr(self, "assert");
}
void block_setMode(PikaObj* self, char* mode) {
obj_setStr(self, "mode", mode);
}
char* block_getMode(PikaObj* self) {
return obj_getStr(self, "mode");
}
void block_pushLine(PikaObj* self, char* line) {
Args* buffs = New_strBuff();
char* body = obj_getStr(self, "body");
body = strsAppend(buffs, body, line);
body = strsAppend(buffs, body, "\n");
obj_setStr(self, "body", body);
obj_setInt(self, "lineSize", obj_getInt(self, "lineSize") + 1);
args_deinit(buffs);
}
char* block_popLine(PikaObj* self) {
Args* buffs = New_strBuff();
char* body = obj_getStr(self, "body");
char* line = strsPopToken(buffs, body, '\n');
obj_setStr(self, "body", body);
obj_setStr(self, "lineNow", line);
obj_setInt(self, "lineSize", obj_getInt(self, "lineSize") - 1);
args_deinit(buffs);
return obj_getStr(self, "lineNow");
}