y_remote.inc 6.1 KB

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