tr_thing.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef tr_thing_H_INCLUDED
  2. #define tr_thing_H_INCLUDED
  3. /* Macros to generate Thing-reated functionality. */
  4. #define TR_THING_GET(THING, STATE, THINGID) \
  5. THING = state_thing(STATE, THINGID); \
  6. if (!THING) { \
  7. return mrb_nil_value(); \
  8. }
  9. #define TR_THING_FUNC_INIT(THING, STATE) \
  10. State * STATE = state_get(); \
  11. Thing * THING = NULL; \
  12. (void) self;
  13. #define TR_THING_IGETTER(NAME, TOCALL) \
  14. static mrb_value NAME(mrb_state * mrb, mrb_value self) { \
  15. TR_THING_FUNC_INIT(thing, state) \
  16. int result; \
  17. mrb_int thingid; \
  18. mrb_get_args(mrb, "i", &thingid); \
  19. TR_THING_GET(thing, state, thingid); \
  20. return mrb_fixnum_value(TOCALL(thing)); \
  21. }
  22. #define TR_THING_II_INT(NAME, TOCALL) \
  23. static mrb_value NAME(mrb_state * mrb, mrb_value self) { \
  24. TR_THING_FUNC_INIT(thing, state) \
  25. mrb_int result; \
  26. mrb_int thingid, i1, i2; \
  27. mrb_get_args(mrb, "iii", &thingid, &i1, &i2); \
  28. TR_THING_GET(thing, state, thingid); \
  29. result = TOCALL(thing, i1, i2); \
  30. return mrb_fixnum_value(result); \
  31. }
  32. #define TR_THING_I_INT(NAME, TOCALL) \
  33. static mrb_value NAME(mrb_state * mrb, mrb_value self) { \
  34. TR_THING_FUNC_INIT(thing, state) \
  35. mrb_int result; \
  36. mrb_int thingid, i1; \
  37. mrb_get_args(mrb, "ii", &thingid, &i1); \
  38. TR_THING_GET(thing, state, thingid); \
  39. result = TOCALL(thing, i1); \
  40. return mrb_fixnum_value(result); \
  41. }
  42. #define TR_THING_I_BOOL(NAME, TOCALL) \
  43. static mrb_value NAME(mrb_state * mrb, mrb_value self) { \
  44. TR_THING_FUNC_INIT(thing, state) \
  45. mrb_int result; \
  46. mrb_int thingid, i1; \
  47. mrb_get_args(mrb, "ii", &thingid, &i1); \
  48. TR_THING_GET(thing, state, thingid); \
  49. result = TOCALL(thing, i1); \
  50. return rh_bool_value(result); \
  51. }
  52. #define TR_THING_III_INT(NAME, TOCALL) \
  53. static mrb_value NAME(mrb_state * mrb, mrb_value self) { \
  54. TR_THING_FUNC_INIT(thing, state) \
  55. mrb_int result; \
  56. mrb_int thingid,i1, i2, i3; \
  57. mrb_get_args(mrb, "iiii", &thingid, &i1, &i2, &i3); \
  58. TR_THING_GET(thing, state, thingid); \
  59. result = TOCALL(thing, i1, i2, i3); \
  60. return mrb_fixnum_value(result); \
  61. }
  62. #define TR_AREA_FUNC_INIT(AREA, STATE) \
  63. State * STATE = state_get(); \
  64. Area * AREA = state_area(STATE); \
  65. (void) self;
  66. #define TR_AREA_II_BOOL(NAME, TOCALL) \
  67. static mrb_value NAME(mrb_state * mrb, mrb_value self) { \
  68. TR_AREA_FUNC_INIT(area, state) \
  69. mrb_int result; \
  70. mrb_int i1, i2; \
  71. mrb_get_args(mrb, "ii", &i1, &i2); \
  72. result = TOCALL(area, i1, i2); \
  73. return rh_bool_value(result); \
  74. }
  75. /* Macros to generate wrappers for area related functionality. */
  76. #define TR_AREA_I_INT(NAME, TOCALL) \
  77. static mrb_value NAME(mrb_state * mrb, mrb_value self) { \
  78. TR_AREA_FUNC_INIT(area, state) \
  79. mrb_int result; \
  80. mrb_int i1; \
  81. mrb_get_args(mrb, "i", &i1); \
  82. result = TOCALL(area, i1); \
  83. return mrb_fixnum_value(result); \
  84. }
  85. #define TR_AREA_II_INT(NAME, TOCALL) \
  86. static mrb_value NAME(mrb_state * mrb, mrb_value self) { \
  87. TR_AREA_FUNC_INIT(area, state) \
  88. mrb_int result; \
  89. mrb_int i1, i2; \
  90. mrb_get_args(mrb, "ii", &i1, &i2); \
  91. result = TOCALL(area, i1, i2); \
  92. return mrb_fixnum_value(result); \
  93. }
  94. #define TR_AREA_III_INT(NAME, TOCALL) \
  95. static mrb_value NAME(mrb_state * mrb, mrb_value self) { \
  96. TR_AREA_FUNC_INIT(area, state) \
  97. mrb_int result; \
  98. mrb_int i1, i2, i3; \
  99. mrb_get_args(mrb, "iii", &i1, &i2, &i3); \
  100. result = TOCALL(area, i1, i2, i3); \
  101. return mrb_fixnum_value(result); \
  102. }
  103. #define TR_AREA_IIII_INT(NAME, TOCALL) \
  104. static mrb_value NAME(mrb_state * mrb, mrb_value self) { \
  105. TR_AREA_FUNC_INIT(area, state) \
  106. mrb_int result; \
  107. mrb_int i1, i2, i3, i4; \
  108. mrb_get_args(mrb, "iiii", &i1, &i2, &i3, &i4); \
  109. result = TOCALL(area, i1, i2, i3, i4); \
  110. return mrb_fixnum_value(result); \
  111. }
  112. int tr_thing_init(mrb_state * mrb, struct RClass * eru);
  113. #endif