Dear me, I should have committed this long ago...
1) Added natives to create and manipulate global and private forward 2) Added natives to call forwards and functions 3) Added an IChanageableForward::RemoveFunction overload for convenience or something 4) Added test suite plugins for functions and forwards 5) Some random touch-ups to some include files --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40627
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Function Call Testing Lab",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Tests basic function calls",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_callfunc", Command_CallFunc);
|
||||
}
|
||||
|
||||
public OnCallFuncReceived(num, Float:fnum, String:str[], String:str2[], &val, &Float:fval, array[], array2[], size, hello2[1])
|
||||
{
|
||||
PrintToServer("Inside OnCallFuncReceived...");
|
||||
|
||||
PrintToServer("num = %d (expected: %d)", num, 5);
|
||||
PrintToServer("fnum = %f (expected: %f)", fnum, 7.17);
|
||||
PrintToServer("str[] = \"%s\" (expected: \"%s\")", str, "Gaben");
|
||||
PrintToServer("str2[] = \"%s\" (expected: \"%s\")", str2, ".taf si nebaG");
|
||||
|
||||
PrintToServer("val = %d (expected %d, setting to %d)", val, 62, 15);
|
||||
val = 15;
|
||||
|
||||
PrintToServer("fval = %f (expected: %f, setting to %f)", fval, 6.25, 1.5);
|
||||
fval = 1.5;
|
||||
|
||||
PrintToServer("Printing %d elements of array[] (expected: %d)", size, 6);
|
||||
for (new i = 0; i < size; i++)
|
||||
{
|
||||
PrintToServer("array[%d] = %d (expected: %d)", i, array[i], i);
|
||||
}
|
||||
for (new i = 0; i < size; i++)
|
||||
{
|
||||
PrintToServer("array2[%d] = %d (expected: %d)", i, array[i], i);
|
||||
}
|
||||
|
||||
/* This shouldn't get copied back */
|
||||
StrCopy(str, strlen(str) + 1, "Yeti");
|
||||
/* This should get copied back */
|
||||
StrCopy(str2, strlen(str2) + 1, "Gaben is fat.");
|
||||
|
||||
/* This should get copied back */
|
||||
array[0] = 5;
|
||||
array[1] = 6;
|
||||
/* This shouldn't get copied back */
|
||||
hello2[0] = 25;
|
||||
|
||||
return 42;
|
||||
}
|
||||
|
||||
public Action:Command_CallFunc(args)
|
||||
{
|
||||
new a = 62;
|
||||
new Float:b = 6.25;
|
||||
new const String:what[] = "Gaben";
|
||||
new String:truth[] = ".taf si nebaG";
|
||||
new hello[] = {0, 1, 2, 3, 4, 5};
|
||||
new hello2[] = {9};
|
||||
new pm = 6;
|
||||
new err;
|
||||
new ret;
|
||||
|
||||
new Function:func = GetFunctionByName(INVALID_HANDLE, "OnCallFuncReceived");
|
||||
|
||||
if (func == INVALID_FUNCTION)
|
||||
{
|
||||
PrintToServer("Failed to get the function id of OnCallFuncReceived");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
PrintToServer("Calling OnCallFuncReceived...");
|
||||
|
||||
Call_StartFunction(INVALID_HANDLE, func);
|
||||
Call_PushCell(5);
|
||||
Call_PushFloat(7.17);
|
||||
Call_PushString(what);
|
||||
Call_PushStringEx(truth, sizeof(truth), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
|
||||
Call_PushCellRef(a);
|
||||
Call_PushFloatRef(b);
|
||||
Call_PushArrayEx(hello, pm, SM_PARAM_COPYBACK);
|
||||
Call_PushArray(hello, pm);
|
||||
Call_PushCell(pm);
|
||||
Call_PushArray(hello2, 1);
|
||||
err = Call_Finish(ret);
|
||||
|
||||
PrintToServer("Call to OnCallFuncReceived has finished!");
|
||||
PrintToServer("Error code = %d (expected: %d)", err, 0);
|
||||
PrintToServer("Return value = %d (expected: %d)", ret, 42);
|
||||
|
||||
PrintToServer("a = %d (expected: %d)", a, 15);
|
||||
PrintToServer("b = %f (expected: %f)", b, 1.5);
|
||||
PrintToServer("what = \"%s\" (expected: \"%s\")", what, "Gaben");
|
||||
PrintToServer("truth = \"%s\" (expected: \"%s\")", truth, "Gaben is fat.");
|
||||
PrintToServer("hello[0] = %d (expected: %d)", hello[0], 5);
|
||||
PrintToServer("hello[1] = %d (expected: %d)", hello[1], 6);
|
||||
PrintToServer("hello2[0] = %d (expected: %d)", hello2[0], 9);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Forward Testing Lab #1",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Tests suite #1 for forwards created by plugins",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
new Handle:g_GlobalFwd = INVALID_HANDLE;
|
||||
new Handle:g_PrivateFwd = INVALID_HANDLE;
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
PrintToServer("OnPluginStart: %d", OnPluginStart);
|
||||
|
||||
RegServerCmd("test_create_gforward", Command_CreateGlobalForward);
|
||||
RegServerCmd("test_create_pforward", Command_CreatePrivateForward);
|
||||
RegServerCmd("test_exec_gforward", Command_ExecGlobalForward);
|
||||
RegServerCmd("test_exec_pforward", Command_ExecPrivateForward);
|
||||
}
|
||||
|
||||
public OnPluginEnd()
|
||||
{
|
||||
CloseHandle(g_GlobalFwd);
|
||||
CloseHandle(g_PrivateFwd);
|
||||
}
|
||||
|
||||
public Action:Command_CreateGlobalForward(args)
|
||||
{
|
||||
if (g_GlobalFwd != INVALID_HANDLE)
|
||||
{
|
||||
CloseHandle(g_GlobalFwd);
|
||||
}
|
||||
|
||||
g_GlobalFwd = CreateGlobalForward("OnGlobalForward", ET_Ignore, Param_Any, Param_Cell, Param_Float, Param_String, Param_Array, Param_CellByRef, Param_FloatByRef);
|
||||
|
||||
if (g_GlobalFwd == INVALID_HANDLE)
|
||||
{
|
||||
PrintToServer("Failed to create global forward!");
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_CreatePrivateForward(args)
|
||||
{
|
||||
new Handle:pl;
|
||||
new Function:func;
|
||||
|
||||
if (g_PrivateFwd != INVALID_HANDLE)
|
||||
{
|
||||
CloseHandle(g_PrivateFwd);
|
||||
}
|
||||
|
||||
g_PrivateFwd = CreateForward(ET_Hook, Param_Cell, Param_String, Param_VarArgs);
|
||||
|
||||
if (g_PrivateFwd == INVALID_HANDLE)
|
||||
{
|
||||
PrintToServer("Failed to create private forward!")
|
||||
}
|
||||
|
||||
pl = FindPluginByFile("fwdtest2.smx");
|
||||
|
||||
if (!pl)
|
||||
{
|
||||
PrintToServer("Could not find fwdtest2.smx!");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
func = GetFunctionByName(pl, "OnPrivateForward");
|
||||
|
||||
/* This shouldn't happen, but oh well */
|
||||
if (func == INVALID_FUNCTION)
|
||||
{
|
||||
PrintToServer("Could not find \"OnPrivateForward\" in fwdtest2.smx!");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
if (!AddToForward(g_PrivateFwd, pl, func) || !AddToForward(g_PrivateFwd, GetMyHandle(), ZohMyGod))
|
||||
{
|
||||
PrintToServer("Failed to add functions to private forward!");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_ExecGlobalForward(args)
|
||||
{
|
||||
new a = 99;
|
||||
new Float:b = 4.215;
|
||||
new err, ret;
|
||||
|
||||
if (g_GlobalFwd == INVALID_HANDLE)
|
||||
{
|
||||
PrintToServer("Failed to execute global forward. Create it first.");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
PrintToServer("Beginning call to %d functions in global forward \"OnGlobalForward\"", GetForwardFunctionCount(g_GlobalFwd));
|
||||
|
||||
Call_StartForward(g_GlobalFwd);
|
||||
Call_PushCell(OnPluginStart);
|
||||
Call_PushCell(7);
|
||||
Call_PushFloat(-8.5);
|
||||
Call_PushString("Anata wa doko desu ka?");
|
||||
Call_PushArray({0.0, 1.1, 2.2}, 3);
|
||||
Call_PushCellRef(a);
|
||||
Call_PushFloatRef(b);
|
||||
err = Call_Finish(ret);
|
||||
|
||||
PrintToServer("Call to global forward \"OnGlobalForward\" completed");
|
||||
PrintToServer("Error code = %d (expected: %d)", err, 0);
|
||||
PrintToServer("Return value = %d (expected: %d)", ret, Plugin_Continue);
|
||||
|
||||
PrintToServer("a = %d (expected: %d)", a, 777);
|
||||
PrintToServer("b = %f (expected: %f)", b, -0.782);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_ExecPrivateForward(args)
|
||||
{
|
||||
new err, ret;
|
||||
|
||||
if (g_PrivateFwd == INVALID_HANDLE)
|
||||
{
|
||||
PrintToServer("Failed to execute private forward. Create it first.");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
PrintToServer("Beginning call to %d functions in private forward", GetForwardFunctionCount(g_PrivateFwd));
|
||||
|
||||
Call_StartForward(g_PrivateFwd);
|
||||
Call_PushCell(24);
|
||||
Call_PushString("I am a format string: %d %d %d %d %d %d");
|
||||
Call_PushCell(0);
|
||||
Call_PushCell(1);
|
||||
Call_PushCell(2);
|
||||
Call_PushCell(3);
|
||||
Call_PushCell(4);
|
||||
Call_PushCell(5);
|
||||
err = Call_Finish(ret);
|
||||
|
||||
PrintToServer("Call to private forward completed");
|
||||
PrintToServer("Error code = %d (expected: %d)", err, 0);
|
||||
PrintToServer("Return value = %d (expected: %d)", ret, Plugin_Handled);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:ZohMyGod(num, const String:format[], ...)
|
||||
{
|
||||
decl String:buffer[128];
|
||||
|
||||
PrintToServer("Inside private forward #1");
|
||||
|
||||
PrintToServer("num = %d (expected: %d)", num, 24);
|
||||
|
||||
VFormat(buffer, sizeof(buffer), format, 3);
|
||||
PrintToServer("buffer = \"%s\" (expected: \"%s\")", buffer, "I am a format string: 0 1 2 3 4 5");
|
||||
|
||||
PrintToServer("End private forward #1");
|
||||
|
||||
return Plugin_Continue;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Forward Testing Lab #2",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Tests suite #2 for forwards created by plugins",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public Action:OnPrivateForward(num, const String:format[], ...)
|
||||
{
|
||||
decl String:buffer[128];
|
||||
|
||||
PrintToServer("Inside private forward #2");
|
||||
|
||||
PrintToServer("num = %d (expected: %d)", num, 24);
|
||||
|
||||
VFormat(buffer, sizeof(buffer), format, 3);
|
||||
PrintToServer("buffer = \"%s\" (expected: \"%s\")", buffer, "I am a format string: 0 1 2 3 4 5");
|
||||
|
||||
PrintToServer("End private forward #2");
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public OnGlobalForward(Function:a, b, Float:c, const String:d[], Float:e[3], &f, &Float:g)
|
||||
{
|
||||
PrintToServer("Inside global forward \"OnGlobalForward\"");
|
||||
|
||||
PrintToServer("a = %d (expected: %d)", a, 11);
|
||||
PrintToServer("b = %d (expected: %d)", b, 7);
|
||||
PrintToServer("c = %f (expected: %f)", c, -8.5);
|
||||
PrintToServer("d = \"%s\" (expected: \"%s\")", d, "Anata wa doko desu ka?");
|
||||
PrintToServer("e = %f %f %f (expected: %f %f %f)", e[0], e[1], e[2], 0.0, 1.1, 2.2);
|
||||
|
||||
PrintToServer("f = %d (expected %d, setting to %d)", f, 99, 777);
|
||||
f = 777;
|
||||
|
||||
PrintToServer("g = %f (expected %f, setting to %f)", g, 4.215, -0.782);
|
||||
g = -0.782;
|
||||
}
|
||||
Reference in New Issue
Block a user