Advertisement
JademusSreg

Galaxy Ref Tests

May 13th, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.13 KB | None | 0 0
  1. int  aFuncInterface(int a);
  2. int  aFunc(int a)   { return a; }
  3. int  bFunc(int a)   { return a*2; }
  4. bool cFunc(int a)   { return true; }
  5. int  dFunc(fixed a) { return FixedToInt(a*3); }
  6.    
  7. void RefTest_Func ()
  8. {
  9.     funcref<aFuncInterface> someFunction = aFunc;
  10.    
  11.     someFunction = bFunc;
  12.   //someFunction = cFunc; type error
  13.   //someFunction = dFunc; type error
  14.    
  15.     someFunction(1);
  16. }
  17.    
  18. typedef funcref<aFuncInterface> int_return_intRef;
  19.    
  20. void RefTest_TypeDefFunc ()
  21. {
  22.     int_return_intRef someFunction = bFunc;
  23.    
  24.     someFunction = aFunc;
  25.    
  26.     someFunction(1);
  27. }
  28.    
  29. void RefTest_FuncArray ()
  30. {
  31.     int_return_intRef[2] someFunction;
  32.    
  33.     someFunction[0] = aFunc;
  34.     someFunction[1] = bFunc;
  35.    
  36.     someFunction[0](1);
  37.     someFunction[1](1);
  38. }
  39.    
  40. int_return_intRef RefTest_FuncReturn ()
  41. {
  42.     return bFunc;
  43. }
  44.    
  45. struct aStruct { int a; string b; };
  46. aStruct aGlobalStruct;
  47. struct bStruct { int a; string b; };
  48. bStruct bGlobalStruct;
  49.    
  50. void RefTest_Struct ()
  51. {
  52.     aStruct aLocalStruct;
  53.     structref<aStruct> someStruct = aLocalStruct;
  54.    
  55.     someStruct = aGlobalStruct;
  56.   //someStruct = bGlobalStruct; bulk copy error
  57. }
  58.    
  59. typedef structref<aStruct> aStructRef;
  60.    
  61. void RefTest_TypeDefStruct ()
  62. {
  63.     aStruct aLocalStruct;
  64.     aStructRef someStruct = aLocalStruct;
  65.    
  66.     someStruct = aGlobalStruct;
  67. }
  68.    
  69. void RefTest_StructArray ()
  70. {
  71.     aStruct aLocalStruct;
  72.     aStructRef[2] someStruct;
  73.    
  74.     someStruct[0] = aLocalStruct;
  75.     someStruct[1] = aGlobalStruct;
  76. }
  77.    
  78. struct funcStruct { int_return_intRef method; };
  79. typedef structref<funcStruct> funcStructRef;
  80.    
  81. void RefTest_StructMethod ()
  82. {
  83.     funcStruct aLocalStruct;
  84.     funcStructRef someStruct;
  85.    
  86.     someStruct.method = bFunc;
  87.    
  88.     someStruct.method(1);
  89. }
  90.    
  91. void RefTest_Parameters (structref<funcStruct> a, funcref<aFuncInterface> b)
  92. {
  93.     funcStructRef someStruct = a;
  94.    
  95.     someStruct.method = b;
  96.    
  97.     someStruct.method(1);
  98. }
  99.    
  100. void RefTest_ParametersWithTypedef (funcStructRef a, int_return_intRef b)
  101. {
  102.     RefTest_Parameters(a,b);
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement