Expose optional default values for the GetEvent* SP functions.

This commit is contained in:
Ryan Stecker
2014-09-12 16:39:21 -05:00
parent 570570f7a0
commit 3ffd4cd835
2 changed files with 36 additions and 8 deletions
+28 -4
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,13 @@ 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 = "";
if (params[0] > 4)
{
pContext->LocalToString(params[5], &defValue);
}
pContext->StringToLocalUTF8(params[3], params[4], pInfo->pEvent->GetString(key, defValue), NULL);
return 1;
}