added ability to use NULL_STRING in KeyValues natives
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401006
This commit is contained in:
+10
-10
@@ -92,7 +92,7 @@ static cell_t smn_KvSetString(IPluginContext *pCtx, const cell_t *params)
|
||||
}
|
||||
|
||||
char *key, *value;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
pCtx->LocalToStringNULL(params[2], &key);
|
||||
pCtx->LocalToString(params[3], &value);
|
||||
|
||||
pStk->pCurRoot.front()->SetString(key, value);
|
||||
@@ -117,7 +117,7 @@ static cell_t smn_KvSetNum(IPluginContext *pCtx, const cell_t *params)
|
||||
}
|
||||
|
||||
char *key;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
pCtx->LocalToStringNULL(params[2], &key);
|
||||
|
||||
pStk->pCurRoot.front()->SetInt(key, params[3]);
|
||||
|
||||
@@ -143,7 +143,7 @@ static cell_t smn_KvSetUInt64(IPluginContext *pCtx, const cell_t *params)
|
||||
char *key;
|
||||
cell_t *addr;
|
||||
uint64 value;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
pCtx->LocalToStringNULL(params[2], &key);
|
||||
pCtx->LocalToPhysAddr(params[3], &addr);
|
||||
|
||||
value = static_cast<uint64>(*addr);
|
||||
@@ -169,7 +169,7 @@ static cell_t smn_KvSetFloat(IPluginContext *pCtx, const cell_t *params)
|
||||
}
|
||||
|
||||
char *key;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
pCtx->LocalToStringNULL(params[2], &key);
|
||||
|
||||
pStk->pCurRoot.front()->SetFloat(key, sp_ctof(params[3]));
|
||||
|
||||
@@ -193,7 +193,7 @@ static cell_t smn_KvSetColor(IPluginContext *pCtx, const cell_t *params)
|
||||
}
|
||||
|
||||
char *key;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
pCtx->LocalToStringNULL(params[2], &key);
|
||||
|
||||
Color color(params[3], params[4], params[5], params[6]);
|
||||
pStk->pCurRoot.front()->SetColor(key, color);
|
||||
@@ -219,7 +219,7 @@ static cell_t smn_KvGetString(IPluginContext *pCtx, const cell_t *params)
|
||||
|
||||
const char *value;
|
||||
char *key, *defvalue;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
pCtx->LocalToStringNULL(params[2], &key);
|
||||
pCtx->LocalToString(params[5], &defvalue);
|
||||
|
||||
value = pStk->pCurRoot.front()->GetString(key, defvalue);
|
||||
@@ -246,7 +246,7 @@ static cell_t smn_KvGetNum(IPluginContext *pCtx, const cell_t *params)
|
||||
|
||||
int value;
|
||||
char *key;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
pCtx->LocalToStringNULL(params[2], &key);
|
||||
|
||||
value = pStk->pCurRoot.front()->GetInt(key, params[3]);
|
||||
|
||||
@@ -271,7 +271,7 @@ static cell_t smn_KvGetFloat(IPluginContext *pCtx, const cell_t *params)
|
||||
|
||||
float value;
|
||||
char *key;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
pCtx->LocalToStringNULL(params[2], &key);
|
||||
|
||||
value = pStk->pCurRoot.front()->GetFloat(key, sp_ctof(params[3]));
|
||||
|
||||
@@ -297,7 +297,7 @@ static cell_t smn_KvGetColor(IPluginContext *pCtx, const cell_t *params)
|
||||
Color color;
|
||||
char *key;
|
||||
cell_t *r, *g, *b, *a;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
pCtx->LocalToStringNULL(params[2], &key);
|
||||
pCtx->LocalToPhysAddr(params[3], &r);
|
||||
pCtx->LocalToPhysAddr(params[4], &g);
|
||||
pCtx->LocalToPhysAddr(params[5], &b);
|
||||
@@ -331,7 +331,7 @@ static cell_t smn_KvGetUInt64(IPluginContext *pCtx, const cell_t *params)
|
||||
char *key;
|
||||
cell_t *addr, *defvalue;
|
||||
uint64 value;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
pCtx->LocalToStringNULL(params[2], &key);
|
||||
pCtx->LocalToPhysAddr(params[3], &addr);
|
||||
pCtx->LocalToPhysAddr(params[4], &defvalue);
|
||||
|
||||
|
||||
@@ -83,6 +83,15 @@ BaseContext::BaseContext(sp_context_t *_ctx)
|
||||
} else {
|
||||
m_pNullVec = NULL;
|
||||
}
|
||||
|
||||
if (FindPubvarByName("NULL_STRING", &index) == SP_ERROR_NONE)
|
||||
{
|
||||
sp_pubvar_t *pubvar;
|
||||
GetPubvarByIndex(index, &pubvar);
|
||||
m_pNullString = pubvar->offs;
|
||||
} else {
|
||||
m_pNullString = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void BaseContext::FlushFunctionCache()
|
||||
@@ -992,6 +1001,22 @@ IPluginFunction *BaseContext::GetFunctionByName(const char *public_name)
|
||||
return pFunc;
|
||||
}
|
||||
|
||||
int BaseContext::LocalToStringNULL(cell_t local_addr, char **addr)
|
||||
{
|
||||
int err;
|
||||
if ((err = LocalToString(local_addr, addr)) != SP_ERROR_NONE)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((cell_t *)*addr == m_pNullString)
|
||||
{
|
||||
*addr = NULL;
|
||||
}
|
||||
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
#if defined SOURCEMOD_BUILD
|
||||
SourceMod::IdentityToken_t *BaseContext::GetIdentity()
|
||||
{
|
||||
|
||||
@@ -70,6 +70,7 @@ namespace SourcePawn
|
||||
SourceMod::IdentityToken_t *GetIdentity();
|
||||
void SetIdentity(SourceMod::IdentityToken_t *token);
|
||||
cell_t *GetNullRef(SP_NULL_TYPE type);
|
||||
int LocalToStringNULL(cell_t local_addr, char **addr);
|
||||
#endif
|
||||
public: //IPluginDebugInfo
|
||||
int LookupFile(ucell_t addr, const char **filename);
|
||||
@@ -86,6 +87,7 @@ namespace SourcePawn
|
||||
#if defined SOURCEMOD_BUILD
|
||||
SourceMod::IdentityToken_t *m_pToken;
|
||||
cell_t *m_pNullVec;
|
||||
cell_t *m_pNullString;
|
||||
#endif
|
||||
char m_MsgCache[1024];
|
||||
bool m_CustomMsg;
|
||||
|
||||
Reference in New Issue
Block a user