Merge pull request #157 from VoiDeD/getevent-defaults

Expose optional default values for the GetEvent* SP functions (r=psychonic)..
This commit is contained in:
Nicholas Hastings 2014-10-05 09:14:30 -04:00
commit ac96bb177a
2 changed files with 37 additions and 8 deletions

View File

@ -207,7 +207,13 @@ static cell_t sm_GetEventBool(IPluginContext *pContext, const cell_t *params)
char *key;
pContext->LocalToString(params[2], &key);
return pInfo->pEvent->GetBool(key);
bool defValue = false;
if (params[0] > 2)
{
defValue = !!params[3];
}
return pInfo->pEvent->GetBool(key, defValue);
}
static cell_t sm_GetEventInt(IPluginContext *pContext, const cell_t *params)
@ -226,7 +232,13 @@ static cell_t sm_GetEventInt(IPluginContext *pContext, const cell_t *params)
char *key;
pContext->LocalToString(params[2], &key);
return pInfo->pEvent->GetInt(key);
int defValue = 0;
if (params[0] > 2)
{
defValue = params[3];
}
return pInfo->pEvent->GetInt(key, defValue);
}
static cell_t sm_GetEventFloat(IPluginContext *pContext, const cell_t *params)
@ -245,7 +257,13 @@ static cell_t sm_GetEventFloat(IPluginContext *pContext, const cell_t *params)
char *key;
pContext->LocalToString(params[2], &key);
float value = pInfo->pEvent->GetFloat(key);
float defValue = 0.0f;
if (params[0] > 2)
{
defValue = sp_ctof(params[3]);
}
float value = pInfo->pEvent->GetFloat(key, defValue);
return sp_ftoc(value);
}
@ -266,7 +284,14 @@ static cell_t sm_GetEventString(IPluginContext *pContext, const cell_t *params)
char *key;
pContext->LocalToString(params[2], &key);
pContext->StringToLocalUTF8(params[3], params[4], pInfo->pEvent->GetString(key), NULL);
char *defValue = NULL;
if (params[0] > 4)
{
pContext->LocalToString(params[5], &defValue);
}
const char *value = pInfo->pEvent->GetString(key, defValue ? defValue : "");
pContext->StringToLocalUTF8(params[3], params[4], value, NULL);
return 1;
}

View File

@ -145,10 +145,11 @@ native CancelCreatedEvent(Handle:event);
*
* @param event Handle to the event.
* @param key Name of event key.
* @param defValue Optional default value to use if the key is not found.
* @return The boolean value of the specfied event key.
* @error Invalid or corrupt Handle.
*/
native bool:GetEventBool(Handle:event, const String:key[]);
native bool:GetEventBool(Handle:event, const String:key[], bool:defValue=false);
/**
* Sets the boolean value of a game event's key.
@ -166,10 +167,11 @@ native SetEventBool(Handle:event, const String:key[], bool:value);
*
* @param event Handle to the event.
* @param key Name of event key.
* @param defValue Optional default value to use if the key is not found.
* @return The integer value of the specfied event key.
* @error Invalid or corrupt Handle.
*/
native GetEventInt(Handle:event, const String:key[]);
native GetEventInt(Handle:event, const String:key[], defValue=0);
/**
* Sets the integer value of a game event's key.
@ -192,10 +194,11 @@ native SetEventInt(Handle:event, const String:key[], value);
*
* @param event Handle to the event.
* @param key Name of event key.
* @param defValue Optional default value to use if the key is not found.
* @return The floating point value of the specfied event key.
* @error Invalid or corrupt Handle.
*/
native Float:GetEventFloat(Handle:event, const String:key[]);
native Float:GetEventFloat(Handle:event, const String:key[], Float:defValue=0.0);
/**
* Sets the floating point value of a game event's key.
@ -215,10 +218,11 @@ native SetEventFloat(Handle:event, const String:key[], Float:value);
* @param key Name of event key.
* @param value Buffer to store the value of the specified event key.
* @param maxlength Maximum length of string buffer.
* @param defValue Optional default value to use if the key is not found.
* @noreturn
* @error Invalid or corrupt Handle.
*/
native GetEventString(Handle:event, const String:key[], String:value[], maxlength);
native GetEventString(Handle:event, const String:key[], String:value[], maxlength, const String:defvalue[]="");
/**
* Sets the string value of a game event's key.