PikaBlock.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Author: lyon
  3. Tencent QQ: 645275593
  4. */
  5. #include "PikaBlock.h"
  6. #include <stdarg.h>
  7. #include "PikaObj.h"
  8. #include "TinyObj.h"
  9. #include "dataArgs.h"
  10. #include "dataMemory.h"
  11. #include "dataString.h"
  12. #include "dataStrs.h"
  13. void block_deinit(PikaObj* self) {
  14. obj_deinit(self);
  15. }
  16. PikaObj* block_init(Args* args) {
  17. PikaObj* self = New_TinyObj(args);
  18. obj_setStr(self, "mode", "");
  19. obj_setStr(self, "assert", "");
  20. obj_setStr(self, "body", "");
  21. obj_setInt(self, "lineSize", 0);
  22. obj_setStr(self, "lineNow", "");
  23. return self;
  24. }
  25. char* block_getBody(PikaObj* self) {
  26. return obj_getStr(self, "body");
  27. }
  28. void block_setBody(PikaObj* self, char* body) {
  29. obj_setStr(self, "body", body);
  30. }
  31. uint8_t block_checkAssert(PikaObj* self) {
  32. Args* buffs = New_strBuff();
  33. PikaObj* host = obj_getContext(self);
  34. char* assert = block_getAssert(self);
  35. obj_run(host, strsFormat(buffs, 32, "_res = %s", assert));
  36. int res = obj_getInt(host, "_res");
  37. obj_removeArg(host, "_res");
  38. args_deinit(buffs);
  39. return res;
  40. }
  41. uint16_t block_getLineSize(PikaObj* self) {
  42. return obj_getInt(self, "lineSize");
  43. }
  44. void block_setAssert(PikaObj* self, char* assert) {
  45. obj_setStr(self, "assert", assert);
  46. }
  47. char* block_getAssert(PikaObj* self) {
  48. return obj_getStr(self, "assert");
  49. }
  50. void block_setMode(PikaObj* self, char* mode) {
  51. obj_setStr(self, "mode", mode);
  52. }
  53. char* block_getMode(PikaObj* self) {
  54. return obj_getStr(self, "mode");
  55. }
  56. void block_pushLine(PikaObj* self, char* line) {
  57. Args* buffs = New_strBuff();
  58. char* body = obj_getStr(self, "body");
  59. body = strsAppend(buffs, body, line);
  60. body = strsAppend(buffs, body, "\n");
  61. obj_setStr(self, "body", body);
  62. obj_setInt(self, "lineSize", obj_getInt(self, "lineSize") + 1);
  63. args_deinit(buffs);
  64. }
  65. char* block_popLine(PikaObj* self) {
  66. Args* buffs = New_strBuff();
  67. char* body = obj_getStr(self, "body");
  68. char* line = strsPopToken(buffs, body, '\n');
  69. obj_setStr(self, "body", body);
  70. obj_setStr(self, "lineNow", line);
  71. obj_setInt(self, "lineSize", obj_getInt(self, "lineSize") - 1);
  72. args_deinit(buffs);
  73. return obj_getStr(self, "lineNow");
  74. }