1
0

y_remote.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #if defined _INC_y_remote
  2. #endinput
  3. #endif
  4. #define _INC_y_remote
  5. /**
  6. * <library name="y_remote">
  7. * <section>
  8. * Description
  9. * </section>
  10. * Wrapper for "__CallRemoteFunction". Enforces some features like no returns
  11. * and arrays being followed by their length.
  12. * <section>
  13. * Version
  14. * </section>
  15. * 1.0
  16. * <section>
  17. * Macros
  18. * </section><ul>
  19. * <symbol name="remotefunc">Define a function to be called remotely (use like "stock").</symbol>
  20. * <symbol name="broadcastfunc">Call the function, but in all scripts.</symbol>
  21. * <symbol name="localfunc">Call the function by name, not address, in the current script.</symbol>
  22. * </ul><section>Compile options</section><ul>
  23. * <symbol name="YSI_NO_MASTER">Disable all knowledge of other scripts.</symbol>
  24. * </ul>
  25. * </library>
  26. *//** *//*
  27. Legal:
  28. Version: MPL 1.1
  29. The contents of this file are subject to the Mozilla Public License Version
  30. 1.1 the "License"; you may not use this file except in compliance with
  31. the License. You may obtain a copy of the License at
  32. http://www.mozilla.org/MPL/
  33. Software distributed under the License is distributed on an "AS IS" basis,
  34. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  35. for the specific language governing rights and limitations under the
  36. License.
  37. The Original Code is the YSI framework.
  38. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  39. Portions created by the Initial Developer are Copyright C 2011
  40. the Initial Developer. All Rights Reserved.
  41. Contributors:
  42. Y_Less
  43. koolk
  44. JoeBullet/Google63
  45. g_aSlice/Slice
  46. Misiur
  47. samphunter
  48. tianmeta
  49. maddinat0r
  50. spacemud
  51. Crayder
  52. Dayvison
  53. Ahmad45123
  54. Zeex
  55. irinel1996
  56. Yiin-
  57. Chaprnks
  58. Konstantinos
  59. Masterchen09
  60. Southclaws
  61. PatchwerkQWER
  62. m0k1
  63. paulommu
  64. udan111
  65. Thanks:
  66. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  67. ZeeX - Very productive conversations.
  68. koolk - IsPlayerinAreaEx code.
  69. TheAlpha - Danish translation.
  70. breadfish - German translation.
  71. Fireburn - Dutch translation.
  72. yom - French translation.
  73. 50p - Polish translation.
  74. Zamaroht - Spanish translation.
  75. Los - Portuguese translation.
  76. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  77. me to strive to better.
  78. Pixels^ - Running XScripters where the idea was born.
  79. Matite - Pestering me to release it and using it.
  80. Very special thanks to:
  81. Thiadmer - PAWN, whose limits continue to amaze me!
  82. Kye/Kalcor - SA:MP.
  83. SA:MP Team past, present and future - SA:MP.
  84. Optional plugins:
  85. Gamer_Z - GPS.
  86. Incognito - Streamer.
  87. Me - sscanf2, fixes2, Whirlpool.
  88. */
  89. #include "..\YSI_Internal\y_version"
  90. #include "..\YSI_Internal\y_shortfunc"
  91. #include "..\YSI_Core\y_utils"
  92. // This VERY LOOSELY uses the master system to figure out if it should even
  93. // bother with complex remote calls. However, it isn't fully bound by the
  94. // whole system because it's rules are different (and will work regardless).
  95. #if defined YSI_NO_MASTER
  96. #define remotefunc stock
  97. #define localfunc%0(%1) (%0(%1))
  98. #define broadcastfunc%0(%1) (%0(%1))
  99. #define targetfunc%3<%2>%0(%1) (%3%0(%1))
  100. #else
  101. // IMPORTANT NOTE! To avoid polluting the global name space (any more that
  102. // is), "y_inline" uses @Ru, @Rv, @Rw, @Rx and @Ry, as both files are low
  103. // usage. "y_testing" uses @Rf-@Ro. "y_phone" uses @R0-@R9 and @RA-@RF
  104. // This now also uses @RH
  105. // This uses "stock" as it may be called from another script.
  106. //#define remotefunc%0(%1) stock%0_(%1)return J@?(W@(_:@Rz:#%0@##,_YM@CR:%1,,)):%0(%1);//%0@(__m);public %0@(__m)if(__m==-1||__m==_@)%0();%0(%1)
  107. #define remotefunc%0(%1) stock%0_(%1)if(@RN:@RO:%0:J@)return(W@(_:@Rz:#%0@##,_YM@CR:%1,,));else return(%0(%1));
  108. #define @RN:@RO:%9void:%0:J@)return(%2);else%8(%3); J@)(%2);else(%3);
  109. #define @RO:%0:J@) J@)
  110. // One macro to rule them all. Instead of doing the parameter validation
  111. // and extraction multiple times, we just do it once and copy the values
  112. // when we're done with them all. The macro is designed to be almost
  113. // entirely right if the function has no parameters.
  114. #define _YM@CR:%0,%1) @Ra:@Rb:@Rc:##|||%0|||%1)
  115. #define @Ra:@Rb:@Rc:#%0#%1|||%3[%4]%9|||%5,%6) @Rd:@Re:#%0#%1|||%3|||%5,%6)
  116. #define @Rd:@Re:#%0#%1|||%2string:%3|||%5,%6) @Ra:@Rb:@Rc:#%0s#%1,%3|||%5|||%6)
  117. #define @Re:#%0#%1|||%3|||%5,%6,%7) @Ra:@Rb:@Rc:#%0a#%1,%3|||%5|||%6,%7)
  118. #define @Rb:@Rc:#%0#%1|||%3|||%5,%6) @Ra:@Rb:@Rc:#%0i#%1,%3|||%5|||%6)
  119. #define @Rc:#%0#,%1||||||));%7(%2(%3)); @RH:@RI:@RJ:#%0#,%1));%7(%2(%3));
  120. // Detect "void:"
  121. #define @RH:@RI:@RJ:#%0#,%1));%7(%9void:%2(%3)); #%0i,%1,I@));%7(%2(%1));%2@(%3,__m);public %2@(%3,__m)if(__m==-1||__m==_@)%2(%1);%2(%3)
  122. // Detect "string:"
  123. #define @RI:@RJ:#%0#,%1));%7(%9string:%2(%3)); #%0i,%1,I@),F@());%7(%2(%1));%2@(%3,__m);public %2@(%3,__m)if(__m==-1||__m==_@)R@(%2(%1));%2(%3)
  124. // Detect other
  125. #define @RJ:#%0#,%1));%7(%2(%3)); #%0i,%1,I@),V@(8,YSIM_RETURN));%7(%2(%1));%2@(%3,__m);public %2@(%3,__m)if(__m==-1||__m==_@)X@(%2(%1));%2(%3)
  126. // Zero parameters.
  127. #define @Rz:#%0##,_YM@CR:,,));%7(%2()); #%0,@RK:@RL:@RM:#i,I@));%7(%2());
  128. // Detect "void:"
  129. #define @RK:@RL:@RM:#i,I@));%7(%9void:%2()); #i,I@));%7(%2());%2@(__m);public %2@(__m)if(__m==-1||__m==_@)%2();%2()
  130. // Detect "string:"
  131. #define @RL:@RM:#i,I@));%7(%9string:%2()); #i,I@),F@());%7(%2());%2@(__m);public %2@(__m)if(__m==-1||__m==_@)R@(%2());%2()
  132. // Detect other
  133. #define @RM:#i,I@));%7(%2()); #i,I@),V@(8,YSIM_RETURN));%7(%2());%2@(__m);public %2@(__m)if(__m==-1||__m==_@)X@(%2());%2()
  134. #define localfunc%0(%1) (J@=0,I@=-1,%0_(%1))
  135. #define broadcastfunc%0(%1) (J@=1,I@=-1,%0_(%1))
  136. // This supports "targetfunc<master> func()" and "targetfunc func<master>()".
  137. #define targetfunc%3<%2>%0(%1) (J@=1,I@=(%2),%3%0_(%1))
  138. #endif