ds@621: #include ds@621: ds@621: public Plugin:myinfo = ds@621: { ds@621: name = "Function Call Testing Lab", ds@621: author = "AlliedModders LLC", ds@621: description = "Tests basic function calls", ds@621: version = "1.0.0.0", ds@621: url = "http://www.sourcemod.net/" ds@621: }; ds@621: ds@621: public OnPluginStart() ds@621: { ds@621: RegServerCmd("test_callfunc", Command_CallFunc); ds@1082: RegServerCmd("test_callfunc_reentrant", Command_ReentrantCallFunc); ds@621: } ds@621: ds@621: public OnCallFuncReceived(num, Float:fnum, String:str[], String:str2[], &val, &Float:fval, array[], array2[], size, hello2[1]) ds@621: { ds@621: PrintToServer("Inside OnCallFuncReceived..."); ds@621: ds@621: PrintToServer("num = %d (expected: %d)", num, 5); ds@621: PrintToServer("fnum = %f (expected: %f)", fnum, 7.17); ds@621: PrintToServer("str[] = \"%s\" (expected: \"%s\")", str, "Gaben"); ds@621: PrintToServer("str2[] = \"%s\" (expected: \"%s\")", str2, ".taf si nebaG"); ds@621: ds@621: PrintToServer("val = %d (expected %d, setting to %d)", val, 62, 15); ds@621: val = 15; ds@621: ds@621: PrintToServer("fval = %f (expected: %f, setting to %f)", fval, 6.25, 1.5); ds@621: fval = 1.5; ds@621: ds@621: PrintToServer("Printing %d elements of array[] (expected: %d)", size, 6); ds@621: for (new i = 0; i < size; i++) ds@621: { ds@621: PrintToServer("array[%d] = %d (expected: %d)", i, array[i], i); ds@621: } ds@621: for (new i = 0; i < size; i++) ds@621: { ds@621: PrintToServer("array2[%d] = %d (expected: %d)", i, array[i], i); ds@621: } ds@621: ds@621: /* This shouldn't get copied back */ ds@1082: strcopy(str, strlen(str) + 1, "Yeti"); ds@621: /* This should get copied back */ ds@1082: strcopy(str2, strlen(str2) + 1, "Gaben is fat."); ds@621: ds@621: /* This should get copied back */ ds@621: array[0] = 5; ds@621: array[1] = 6; ds@621: /* This shouldn't get copied back */ ds@621: hello2[0] = 25; ds@621: ds@621: return 42; ds@621: } ds@621: ds@1082: public OnReentrantCallReceived(num, String:str[]) ds@1082: { ds@1082: new err, ret; ds@1082: ds@1082: PrintToServer("Inside OnReentrantCallReceived..."); ds@1082: ds@1082: PrintToServer("num = %d (expected: %d)", num, 7); ds@1082: PrintToServer("str[] = \"%s\" (expected: \"%s\")", str, "nana"); ds@1082: ds@1082: new Function:func = GetFunctionByName(INVALID_HANDLE, "OnReentrantCallReceivedTwo"); ds@1082: ds@1082: if (func == INVALID_FUNCTION) ds@1082: { ds@1082: PrintToServer("Failed to get the function id of OnReentrantCallReceivedTwo"); ds@1082: return 0; ds@1082: } ds@1082: ds@1082: PrintToServer("Calling OnReentrantCallReceivedTwo..."); ds@1082: ds@1082: Call_StartFunction(INVALID_HANDLE, func); ds@1082: Call_PushFloat(8.0); ds@1082: err = Call_Finish(ret); ds@1082: ds@1082: PrintToServer("Call to OnReentrantCallReceivedTwo has finished!"); ds@1082: PrintToServer("Error code = %d (expected: %d)", err, 0); ds@1082: PrintToServer("Return value = %d (expected: %d)", ret, 707); ds@1082: ds@1082: return 11; ds@1082: } ds@1082: ds@1082: public OnReentrantCallReceivedTwo(Float:fnum) ds@1082: { ds@1082: PrintToServer("Inside OnReentrantCallReceivedTwo..."); ds@1082: ds@1082: PrintToServer("fnum = %f (expected: %f)", fnum, 8.0); ds@1082: ds@1082: return 707; ds@1082: } ds@1082: ds@621: public Action:Command_CallFunc(args) ds@621: { ds@621: new a = 62; ds@621: new Float:b = 6.25; ds@621: new const String:what[] = "Gaben"; ds@621: new String:truth[] = ".taf si nebaG"; ds@621: new hello[] = {0, 1, 2, 3, 4, 5}; ds@621: new hello2[] = {9}; ds@621: new pm = 6; ds@621: new err; ds@621: new ret; ds@621: ds@621: new Function:func = GetFunctionByName(INVALID_HANDLE, "OnCallFuncReceived"); ds@621: ds@621: if (func == INVALID_FUNCTION) ds@621: { ds@621: PrintToServer("Failed to get the function id of OnCallFuncReceived"); ds@621: return Plugin_Handled; ds@621: } ds@621: ds@621: PrintToServer("Calling OnCallFuncReceived..."); ds@621: ds@621: Call_StartFunction(INVALID_HANDLE, func); ds@621: Call_PushCell(5); ds@621: Call_PushFloat(7.17); ds@621: Call_PushString(what); ds@621: Call_PushStringEx(truth, sizeof(truth), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); ds@621: Call_PushCellRef(a); ds@621: Call_PushFloatRef(b); ds@621: Call_PushArrayEx(hello, pm, SM_PARAM_COPYBACK); ds@621: Call_PushArray(hello, pm); ds@621: Call_PushCell(pm); ds@621: Call_PushArray(hello2, 1); ds@621: err = Call_Finish(ret); ds@621: ds@621: PrintToServer("Call to OnCallFuncReceived has finished!"); ds@621: PrintToServer("Error code = %d (expected: %d)", err, 0); ds@621: PrintToServer("Return value = %d (expected: %d)", ret, 42); ds@621: ds@621: PrintToServer("a = %d (expected: %d)", a, 15); ds@621: PrintToServer("b = %f (expected: %f)", b, 1.5); ds@621: PrintToServer("what = \"%s\" (expected: \"%s\")", what, "Gaben"); ds@621: PrintToServer("truth = \"%s\" (expected: \"%s\")", truth, "Gaben is fat."); ds@621: PrintToServer("hello[0] = %d (expected: %d)", hello[0], 5); ds@621: PrintToServer("hello[1] = %d (expected: %d)", hello[1], 6); ds@621: PrintToServer("hello2[0] = %d (expected: %d)", hello2[0], 9); ds@621: ds@621: return Plugin_Handled; ds@621: } ds@1082: ds@1082: public Action:Command_ReentrantCallFunc(args) ds@1082: { ds@1082: new err, ret; ds@1082: new Function:func = GetFunctionByName(INVALID_HANDLE, "OnReentrantCallReceived"); ds@1082: ds@1082: if (func == INVALID_FUNCTION) ds@1082: { ds@1082: PrintToServer("Failed to get the function id of OnReentrantCallReceived"); ds@1082: return Plugin_Handled; ds@1082: } ds@1082: ds@1082: PrintToServer("Calling OnReentrantCallReceived..."); ds@1082: ds@1082: Call_StartFunction(INVALID_HANDLE, func); ds@1082: Call_PushCell(7); ds@1082: Call_PushString("nana"); ds@1082: err = Call_Finish(ret); ds@1082: ds@1082: PrintToServer("Call to OnReentrantCallReceived has finished!"); ds@1082: PrintToServer("Error code = %d (expected: %d)", err, 0); ds@1082: PrintToServer("Return value = %d (expected: %d)", ret, 11); ds@1082: ds@1082: return Plugin_Handled; ds@1082: }