5 name = "Function Call Testing Lab",
6 author = "AlliedModders LLC",
7 description = "Tests basic function calls",
9 url = "http://www.sourcemod.net/"
12 public OnPluginStart()
14 RegServerCmd("test_callfunc", Command_CallFunc);
15 RegServerCmd("test_callfunc_reentrant", Command_ReentrantCallFunc);
18 public OnCallFuncReceived(num, Float:fnum, String:str[], String:str2[], &val, &Float:fval, array[], array2[], size, hello2[1])
20 PrintToServer("Inside OnCallFuncReceived...");
22 PrintToServer("num = %d (expected: %d)", num, 5);
23 PrintToServer("fnum = %f (expected: %f)", fnum, 7.17);
24 PrintToServer("str[] = \"%s\" (expected: \"%s\")", str, "Gaben");
25 PrintToServer("str2[] = \"%s\" (expected: \"%s\")", str2, ".taf si nebaG");
27 PrintToServer("val = %d (expected %d, setting to %d)", val, 62, 15);
30 PrintToServer("fval = %f (expected: %f, setting to %f)", fval, 6.25, 1.5);
33 PrintToServer("Printing %d elements of array[] (expected: %d)", size, 6);
34 for (new i = 0; i < size; i++)
36 PrintToServer("array[%d] = %d (expected: %d)", i, array[i], i);
38 for (new i = 0; i < size; i++)
40 PrintToServer("array2[%d] = %d (expected: %d)", i, array[i], i);
43 /* This shouldn't get copied back */
44 strcopy(str, strlen(str) + 1, "Yeti");
45 /* This should get copied back */
46 strcopy(str2, strlen(str2) + 1, "Gaben is fat.");
48 /* This should get copied back */
51 /* This shouldn't get copied back */
57 public OnReentrantCallReceived(num, String:str[])
61 PrintToServer("Inside OnReentrantCallReceived...");
63 PrintToServer("num = %d (expected: %d)", num, 7);
64 PrintToServer("str[] = \"%s\" (expected: \"%s\")", str, "nana");
66 new Function:func = GetFunctionByName(INVALID_HANDLE, "OnReentrantCallReceivedTwo");
68 if (func == INVALID_FUNCTION)
70 PrintToServer("Failed to get the function id of OnReentrantCallReceivedTwo");
74 PrintToServer("Calling OnReentrantCallReceivedTwo...");
76 Call_StartFunction(INVALID_HANDLE, func);
78 err = Call_Finish(ret);
80 PrintToServer("Call to OnReentrantCallReceivedTwo has finished!");
81 PrintToServer("Error code = %d (expected: %d)", err, 0);
82 PrintToServer("Return value = %d (expected: %d)", ret, 707);
87 public OnReentrantCallReceivedTwo(Float:fnum)
89 PrintToServer("Inside OnReentrantCallReceivedTwo...");
91 PrintToServer("fnum = %f (expected: %f)", fnum, 8.0);
96 public Action:Command_CallFunc(args)
100 new const String:what[] = "Gaben";
101 new String:truth[] = ".taf si nebaG";
102 new hello[] = {0, 1, 2, 3, 4, 5};
108 new Function:func = GetFunctionByName(INVALID_HANDLE, "OnCallFuncReceived");
110 if (func == INVALID_FUNCTION)
112 PrintToServer("Failed to get the function id of OnCallFuncReceived");
113 return Plugin_Handled;
116 PrintToServer("Calling OnCallFuncReceived...");
118 Call_StartFunction(INVALID_HANDLE, func);
120 Call_PushFloat(7.17);
121 Call_PushString(what);
122 Call_PushStringEx(truth, sizeof(truth), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
124 Call_PushFloatRef(b);
125 Call_PushArrayEx(hello, pm, SM_PARAM_COPYBACK);
126 Call_PushArray(hello, pm);
128 Call_PushArray(hello2, 1);
129 err = Call_Finish(ret);
131 PrintToServer("Call to OnCallFuncReceived has finished!");
132 PrintToServer("Error code = %d (expected: %d)", err, 0);
133 PrintToServer("Return value = %d (expected: %d)", ret, 42);
135 PrintToServer("a = %d (expected: %d)", a, 15);
136 PrintToServer("b = %f (expected: %f)", b, 1.5);
137 PrintToServer("what = \"%s\" (expected: \"%s\")", what, "Gaben");
138 PrintToServer("truth = \"%s\" (expected: \"%s\")", truth, "Gaben is fat.");
139 PrintToServer("hello[0] = %d (expected: %d)", hello[0], 5);
140 PrintToServer("hello[1] = %d (expected: %d)", hello[1], 6);
141 PrintToServer("hello2[0] = %d (expected: %d)", hello2[0], 9);
143 return Plugin_Handled;
146 public Action:Command_ReentrantCallFunc(args)
149 new Function:func = GetFunctionByName(INVALID_HANDLE, "OnReentrantCallReceived");
151 if (func == INVALID_FUNCTION)
153 PrintToServer("Failed to get the function id of OnReentrantCallReceived");
154 return Plugin_Handled;
157 PrintToServer("Calling OnReentrantCallReceived...");
159 Call_StartFunction(INVALID_HANDLE, func);
161 Call_PushString("nana");
162 err = Call_Finish(ret);
164 PrintToServer("Call to OnReentrantCallReceived has finished!");
165 PrintToServer("Error code = %d (expected: %d)", err, 0);
166 PrintToServer("Return value = %d (expected: %d)", ret, 11);
168 return Plugin_Handled;