|
ds@621
|
1 |
#include <sourcemod> |
|
ds@621
|
2 |
|
|
ds@621
|
3 |
public Plugin:myinfo = |
|
ds@621
|
4 |
{ |
|
ds@621
|
5 |
name = "Function Call Testing Lab", |
|
ds@621
|
6 |
author = "AlliedModders LLC", |
|
ds@621
|
7 |
description = "Tests basic function calls", |
|
ds@621
|
8 |
version = "1.0.0.0", |
|
ds@621
|
9 |
url = "http://www.sourcemod.net/" |
|
ds@621
|
10 |
}; |
|
ds@621
|
11 |
|
|
ds@621
|
12 |
public OnPluginStart() |
|
ds@621
|
13 |
{ |
|
ds@621
|
14 |
RegServerCmd("test_callfunc", Command_CallFunc); |
|
ds@621
|
15 |
} |
|
ds@621
|
16 |
|
|
ds@621
|
17 |
public OnCallFuncReceived(num, Float:fnum, String:str[], String:str2[], &val, &Float:fval, array[], array2[], size, hello2[1]) |
|
ds@621
|
18 |
{ |
|
ds@621
|
19 |
PrintToServer("Inside OnCallFuncReceived..."); |
|
ds@621
|
20 |
|
|
ds@621
|
21 |
PrintToServer("num = %d (expected: %d)", num, 5); |
|
ds@621
|
22 |
PrintToServer("fnum = %f (expected: %f)", fnum, 7.17); |
|
ds@621
|
23 |
PrintToServer("str[] = \"%s\" (expected: \"%s\")", str, "Gaben"); |
|
ds@621
|
24 |
PrintToServer("str2[] = \"%s\" (expected: \"%s\")", str2, ".taf si nebaG"); |
|
ds@621
|
25 |
|
|
ds@621
|
26 |
PrintToServer("val = %d (expected %d, setting to %d)", val, 62, 15); |
|
ds@621
|
27 |
val = 15; |
|
ds@621
|
28 |
|
|
ds@621
|
29 |
PrintToServer("fval = %f (expected: %f, setting to %f)", fval, 6.25, 1.5); |
|
ds@621
|
30 |
fval = 1.5; |
|
ds@621
|
31 |
|
|
ds@621
|
32 |
PrintToServer("Printing %d elements of array[] (expected: %d)", size, 6); |
|
ds@621
|
33 |
for (new i = 0; i < size; i++) |
|
ds@621
|
34 |
{ |
|
ds@621
|
35 |
PrintToServer("array[%d] = %d (expected: %d)", i, array[i], i); |
|
ds@621
|
36 |
} |
|
ds@621
|
37 |
for (new i = 0; i < size; i++) |
|
ds@621
|
38 |
{ |
|
ds@621
|
39 |
PrintToServer("array2[%d] = %d (expected: %d)", i, array[i], i); |
|
ds@621
|
40 |
} |
|
ds@621
|
41 |
|
|
ds@621
|
42 |
/* This shouldn't get copied back */ |
|
ds@621
|
43 |
StrCopy(str, strlen(str) + 1, "Yeti"); |
|
ds@621
|
44 |
/* This should get copied back */ |
|
ds@621
|
45 |
StrCopy(str2, strlen(str2) + 1, "Gaben is fat."); |
|
ds@621
|
46 |
|
|
ds@621
|
47 |
/* This should get copied back */ |
|
ds@621
|
48 |
array[0] = 5; |
|
ds@621
|
49 |
array[1] = 6; |
|
ds@621
|
50 |
/* This shouldn't get copied back */ |
|
ds@621
|
51 |
hello2[0] = 25; |
|
ds@621
|
52 |
|
|
ds@621
|
53 |
return 42; |
|
ds@621
|
54 |
} |
|
ds@621
|
55 |
|
|
ds@621
|
56 |
public Action:Command_CallFunc(args) |
|
ds@621
|
57 |
{ |
|
ds@621
|
58 |
new a = 62; |
|
ds@621
|
59 |
new Float:b = 6.25; |
|
ds@621
|
60 |
new const String:what[] = "Gaben"; |
|
ds@621
|
61 |
new String:truth[] = ".taf si nebaG"; |
|
ds@621
|
62 |
new hello[] = {0, 1, 2, 3, 4, 5}; |
|
ds@621
|
63 |
new hello2[] = {9}; |
|
ds@621
|
64 |
new pm = 6; |
|
ds@621
|
65 |
new err; |
|
ds@621
|
66 |
new ret; |
|
ds@621
|
67 |
|
|
ds@621
|
68 |
new Function:func = GetFunctionByName(INVALID_HANDLE, "OnCallFuncReceived"); |
|
ds@621
|
69 |
|
|
ds@621
|
70 |
if (func == INVALID_FUNCTION) |
|
ds@621
|
71 |
{ |
|
ds@621
|
72 |
PrintToServer("Failed to get the function id of OnCallFuncReceived"); |
|
ds@621
|
73 |
return Plugin_Handled; |
|
ds@621
|
74 |
} |
|
ds@621
|
75 |
|
|
ds@621
|
76 |
PrintToServer("Calling OnCallFuncReceived..."); |
|
ds@621
|
77 |
|
|
ds@621
|
78 |
Call_StartFunction(INVALID_HANDLE, func); |
|
ds@621
|
79 |
Call_PushCell(5); |
|
ds@621
|
80 |
Call_PushFloat(7.17); |
|
ds@621
|
81 |
Call_PushString(what); |
|
ds@621
|
82 |
Call_PushStringEx(truth, sizeof(truth), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); |
|
ds@621
|
83 |
Call_PushCellRef(a); |
|
ds@621
|
84 |
Call_PushFloatRef(b); |
|
ds@621
|
85 |
Call_PushArrayEx(hello, pm, SM_PARAM_COPYBACK); |
|
ds@621
|
86 |
Call_PushArray(hello, pm); |
|
ds@621
|
87 |
Call_PushCell(pm); |
|
ds@621
|
88 |
Call_PushArray(hello2, 1); |
|
ds@621
|
89 |
err = Call_Finish(ret); |
|
ds@621
|
90 |
|
|
ds@621
|
91 |
PrintToServer("Call to OnCallFuncReceived has finished!"); |
|
ds@621
|
92 |
PrintToServer("Error code = %d (expected: %d)", err, 0); |
|
ds@621
|
93 |
PrintToServer("Return value = %d (expected: %d)", ret, 42); |
|
ds@621
|
94 |
|
|
ds@621
|
95 |
PrintToServer("a = %d (expected: %d)", a, 15); |
|
ds@621
|
96 |
PrintToServer("b = %f (expected: %f)", b, 1.5); |
|
ds@621
|
97 |
PrintToServer("what = \"%s\" (expected: \"%s\")", what, "Gaben"); |
|
ds@621
|
98 |
PrintToServer("truth = \"%s\" (expected: \"%s\")", truth, "Gaben is fat."); |
|
ds@621
|
99 |
PrintToServer("hello[0] = %d (expected: %d)", hello[0], 5); |
|
ds@621
|
100 |
PrintToServer("hello[1] = %d (expected: %d)", hello[1], 6); |
|
ds@621
|
101 |
PrintToServer("hello2[0] = %d (expected: %d)", hello2[0], 9); |
|
ds@621
|
102 |
|
|
ds@621
|
103 |
return Plugin_Handled; |
|
ds@621
|
104 |
} |