Skip to content

Commit 8ed8899

Browse files
FyrenHeadline
authored andcommitted
Add KeyValues.Merge
1 parent 9a03d12 commit 8ed8899

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

core/smn_keyvalues.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,34 @@ static cell_t smn_KvGetSectionSymbol(IPluginContext *pCtx, const cell_t *params)
11131113
return 1;
11141114
}
11151115

1116+
static cell_t KeyValues_Merge(IPluginContext *pContext, const cell_t *params)
1117+
{
1118+
Handle_t hndl_this = static_cast<Handle_t>(params[1]);
1119+
Handle_t hndl_other = static_cast<Handle_t>(params[2]);
1120+
HandleError herr;
1121+
HandleSecurity sec;
1122+
KeyValueStack *pStk_this, *pStk_other;
1123+
1124+
sec.pOwner = NULL;
1125+
sec.pIdentity = g_pCoreIdent;
1126+
1127+
if ((herr=handlesys->ReadHandle(hndl_this, g_KeyValueType, &sec, (void **)&pStk_this))
1128+
!= HandleError_None)
1129+
{
1130+
return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl_this, herr);
1131+
}
1132+
if ((herr=handlesys->ReadHandle(hndl_other, g_KeyValueType, &sec, (void **)&pStk_other))
1133+
!= HandleError_None)
1134+
{
1135+
return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl_other, herr);
1136+
}
1137+
1138+
pStk_this->pCurRoot.front()->RecursiveMergeKeyValues(pStk_other->pCurRoot.front());
1139+
1140+
return 1;
1141+
1142+
}
1143+
11161144
static cell_t KeyValues_Import(IPluginContext *pContext, const cell_t *params)
11171145
{
11181146
// This version takes (dest, src). The original is (src, dest).
@@ -1256,6 +1284,7 @@ REGISTER_NATIVES(keyvaluenatives)
12561284
{"KeyValues.ExportToFile", smn_KeyValuesToFile},
12571285
{"KeyValues.ExportToString", smn_KeyValuesToString},
12581286
{"KeyValues.ExportLength.get", smn_KeyValuesExportLength},
1287+
{"KeyValues.Merge", KeyValues_Merge},
12591288

12601289
{NULL, NULL}
12611290
};

plugins/include/keyvalues.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ methodmap KeyValues < Handle
334334
// @param id Id of the current section.
335335
// @return True on success, false on failure.
336336
public native bool GetSectionSymbol(int &id);
337+
338+
// Merge from the current position of another KeyValues into the current
339+
// position of this one.
340+
//
341+
// @param other KeyValues Handle to merge from.
342+
public native void Merge(KeyValues other);
337343
};
338344

339345
/**

0 commit comments

Comments
 (0)