Create GlobalForward & PrivateForward methodmaps (#1004)
This commit is contained in:
parent
81dc80fbd1
commit
4f3c3175e6
@ -733,27 +733,36 @@ static cell_t sm_AddFrameAction(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
REGISTER_NATIVES(functionNatives)
|
||||
{
|
||||
{"GetFunctionByName", sm_GetFunctionByName},
|
||||
{"CreateGlobalForward", sm_CreateGlobalForward},
|
||||
{"CreateForward", sm_CreateForward},
|
||||
{"GetForwardFunctionCount", sm_GetForwardFunctionCount},
|
||||
{"AddToForward", sm_AddToForward},
|
||||
{"RemoveFromForward", sm_RemoveFromForward},
|
||||
{"RemoveAllFromForward", sm_RemoveAllFromForward},
|
||||
{"Call_StartFunction", sm_CallStartFunction},
|
||||
{"Call_StartForward", sm_CallStartForward},
|
||||
{"Call_PushCell", sm_CallPushCell},
|
||||
{"Call_PushCellRef", sm_CallPushCellRef},
|
||||
{"Call_PushFloat", sm_CallPushFloat},
|
||||
{"Call_PushFloatRef", sm_CallPushFloatRef},
|
||||
{"Call_PushArray", sm_CallPushArray},
|
||||
{"Call_PushArrayEx", sm_CallPushArrayEx},
|
||||
{"Call_PushString", sm_CallPushString},
|
||||
{"Call_PushStringEx", sm_CallPushStringEx},
|
||||
{"Call_PushNullVector", sm_CallPushNullVector},
|
||||
{"Call_PushNullString", sm_CallPushNullString},
|
||||
{"Call_Finish", sm_CallFinish},
|
||||
{"Call_Cancel", sm_CallCancel},
|
||||
{"RequestFrame", sm_AddFrameAction},
|
||||
{NULL, NULL},
|
||||
{"GetFunctionByName", sm_GetFunctionByName},
|
||||
{"CreateGlobalForward", sm_CreateGlobalForward},
|
||||
{"CreateForward", sm_CreateForward},
|
||||
{"GetForwardFunctionCount", sm_GetForwardFunctionCount},
|
||||
{"AddToForward", sm_AddToForward},
|
||||
{"RemoveFromForward", sm_RemoveFromForward},
|
||||
{"RemoveAllFromForward", sm_RemoveAllFromForward},
|
||||
{"Call_StartFunction", sm_CallStartFunction},
|
||||
{"Call_StartForward", sm_CallStartForward},
|
||||
{"Call_PushCell", sm_CallPushCell},
|
||||
{"Call_PushCellRef", sm_CallPushCellRef},
|
||||
{"Call_PushFloat", sm_CallPushFloat},
|
||||
{"Call_PushFloatRef", sm_CallPushFloatRef},
|
||||
{"Call_PushArray", sm_CallPushArray},
|
||||
{"Call_PushArrayEx", sm_CallPushArrayEx},
|
||||
{"Call_PushString", sm_CallPushString},
|
||||
{"Call_PushStringEx", sm_CallPushStringEx},
|
||||
{"Call_PushNullVector", sm_CallPushNullVector},
|
||||
{"Call_PushNullString", sm_CallPushNullString},
|
||||
{"Call_Finish", sm_CallFinish},
|
||||
{"Call_Cancel", sm_CallCancel},
|
||||
{"RequestFrame", sm_AddFrameAction},
|
||||
|
||||
{"GlobalForward.GlobalForward", sm_CreateGlobalForward},
|
||||
{"GlobalForward.FunctionCount.get", sm_GetForwardFunctionCount},
|
||||
|
||||
{"PrivateForward.PrivateForward", sm_CreateForward},
|
||||
{"PrivateForward.AddFunction", sm_AddToForward},
|
||||
{"PrivateForward.RemoveFunction", sm_RemoveFromForward},
|
||||
{"PrivateForward.RemoveAllFunctions", sm_RemoveAllFromForward},
|
||||
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
@ -48,8 +48,8 @@ public Plugin myinfo =
|
||||
};
|
||||
|
||||
/* Forwards */
|
||||
Handle hOnAdminMenuReady = null;
|
||||
Handle hOnAdminMenuCreated = null;
|
||||
GlobalForward hOnAdminMenuReady;
|
||||
GlobalForward hOnAdminMenuCreated;
|
||||
|
||||
/* Menus */
|
||||
TopMenu hAdminMenu;
|
||||
@ -75,8 +75,8 @@ public void OnPluginStart()
|
||||
LoadTranslations("common.phrases");
|
||||
LoadTranslations("adminmenu.phrases");
|
||||
|
||||
hOnAdminMenuCreated = CreateGlobalForward("OnAdminMenuCreated", ET_Ignore, Param_Cell);
|
||||
hOnAdminMenuReady = CreateGlobalForward("OnAdminMenuReady", ET_Ignore, Param_Cell);
|
||||
hOnAdminMenuCreated = new GlobalForward("OnAdminMenuCreated", ET_Ignore, Param_Cell);
|
||||
hOnAdminMenuReady = new GlobalForward("OnAdminMenuReady", ET_Ignore, Param_Cell);
|
||||
|
||||
RegAdminCmd("sm_admin", Command_DisplayMenu, ADMFLAG_GENERIC, "Displays the admin menu");
|
||||
}
|
||||
|
@ -111,6 +111,74 @@ enum ExecType
|
||||
* @endsection
|
||||
*/
|
||||
|
||||
methodmap GlobalForward < Handle {
|
||||
// Creates a global forward.
|
||||
//
|
||||
// @note The name used to create the forward is used as its public function in all target plugins.
|
||||
// @note This is ideal for global, static forwards that are never changed.
|
||||
// @note Global forwards cannot be cloned.
|
||||
// @note Use CloseHandle() to destroy these.
|
||||
//
|
||||
// @param name Name of public function to use in forward.
|
||||
// @param type Execution type to be used.
|
||||
// @param ... Variable number of parameter types (up to 32).
|
||||
// @return Handle to new global forward.
|
||||
// @error More than 32 paramater types passed.
|
||||
public native GlobalForward(const char[] name, ExecType type, ParamType ...);
|
||||
|
||||
// Returns the number of functions in a global or private forward's call list.
|
||||
property int FunctionCount {
|
||||
public native get();
|
||||
}
|
||||
};
|
||||
|
||||
methodmap PrivateForward < GlobalForward {
|
||||
// Creates a private forward.
|
||||
//
|
||||
// @note No functions are automatically added. Use AddToForward() to do this.
|
||||
// @note Private forwards can be cloned.
|
||||
// @note Use CloseHandle() to destroy these.
|
||||
//
|
||||
// @param type Execution type to be used.
|
||||
// @param ... Variable number of parameter types (up to 32).
|
||||
// @return Handle to new private forward.
|
||||
// @error More than 32 paramater types passed.
|
||||
public native PrivateForward(ExecType type, ParamType ...);
|
||||
|
||||
// Adds a function to a private forward's call list.
|
||||
//
|
||||
// @note Cannot be used during an incomplete call.
|
||||
//
|
||||
// @param plugin Handle of the plugin that contains the function.
|
||||
// Pass INVALID_HANDLE to specify the calling plugin.
|
||||
// @param func Function to add to forward.
|
||||
// @return True on success, false otherwise.
|
||||
// @error Invalid or corrupt private forward handle, invalid or corrupt plugin handle, or invalid function.
|
||||
public native bool AddFunction(Handle plugin, Function func);
|
||||
|
||||
// Removes a function from a private forward's call list.
|
||||
//
|
||||
// @note Only removes one instance.
|
||||
// @note Functions will be removed automatically if their parent plugin is unloaded.
|
||||
//
|
||||
// @param plugin Handle of the plugin that contains the function.
|
||||
// Pass INVALID_HANDLE to specify the calling plugin.
|
||||
// @param func Function to remove from forward.
|
||||
// @return True on success, false otherwise.
|
||||
// @error Invalid or corrupt private forward handle, invalid or corrupt plugin handle, or invalid function.
|
||||
public native bool RemoveFunction(Handle plugin, Function func);
|
||||
|
||||
// Removes all instances of a plugin from a private forward's call list.
|
||||
//
|
||||
// @note Functions will be removed automatically if their parent plugin is unloaded.
|
||||
//
|
||||
// @param plugin Handle of the plugin to remove instances of.
|
||||
// Pass INVALID_HANDLE to specify the calling plugin.
|
||||
// @return Number of functions removed from forward.
|
||||
// @error Invalid or corrupt private forward handle or invalid or corrupt plugin handle.
|
||||
public native int RemoveAllFunctions(Handle plugin);
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a function id from a function name.
|
||||
*
|
||||
@ -136,7 +204,7 @@ native Function GetFunctionByName(Handle plugin, const char[] name);
|
||||
* @return Handle to new global forward.
|
||||
* @error More than 32 paramater types passed.
|
||||
*/
|
||||
native Handle CreateGlobalForward(const char[] name, ExecType type, ParamType ...);
|
||||
native GlobalForward CreateGlobalForward(const char[] name, ExecType type, ParamType ...);
|
||||
|
||||
/**
|
||||
* Creates a private forward.
|
||||
@ -150,7 +218,7 @@ native Handle CreateGlobalForward(const char[] name, ExecType type, ParamType ..
|
||||
* @return Handle to new private forward.
|
||||
* @error More than 32 paramater types passed.
|
||||
*/
|
||||
native Handle CreateForward(ExecType type, ParamType ...);
|
||||
native PrivateForward CreateForward(ExecType type, ParamType ...);
|
||||
|
||||
/**
|
||||
* Returns the number of functions in a global or private forward's call list.
|
||||
|
@ -95,8 +95,8 @@ int g_mapFileSerial = -1;
|
||||
|
||||
MapChange g_ChangeTime;
|
||||
|
||||
Handle g_NominationsResetForward = null;
|
||||
Handle g_MapVoteStartedForward = null;
|
||||
GlobalForward g_NominationsResetForward;
|
||||
GlobalForward g_MapVoteStartedForward;
|
||||
|
||||
/* Upper bound of how many team there could be */
|
||||
#define MAXTEAMS 10
|
||||
@ -181,8 +181,8 @@ public void OnPluginStart()
|
||||
g_Cvar_Bonusroundtime.SetBounds(ConVarBound_Upper, true, 30.0);
|
||||
}
|
||||
|
||||
g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
|
||||
g_MapVoteStartedForward = CreateGlobalForward("OnMapVoteStarted", ET_Ignore);
|
||||
g_NominationsResetForward = new GlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
|
||||
g_MapVoteStartedForward = new GlobalForward("OnMapVoteStarted", ET_Ignore);
|
||||
}
|
||||
|
||||
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
|
||||
|
Loading…
Reference in New Issue
Block a user