Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KeyValues.Merge #2184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions core/smn_keyvalues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,34 @@ static cell_t smn_KvGetSectionSymbol(IPluginContext *pCtx, const cell_t *params)
return 1;
}

static cell_t KeyValues_Merge(IPluginContext *pContext, const cell_t *params)
{
Handle_t hndl_this = static_cast<Handle_t>(params[1]);
Handle_t hndl_other = static_cast<Handle_t>(params[2]);
HandleError herr;
HandleSecurity sec;
KeyValueStack *pStk_this, *pStk_other;

sec.pOwner = NULL;
sec.pIdentity = g_pCoreIdent;

if ((herr=handlesys->ReadHandle(hndl_this, g_KeyValueType, &sec, (void **)&pStk_this))
!= HandleError_None)
{
return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl_this, herr);
}
if ((herr=handlesys->ReadHandle(hndl_other, g_KeyValueType, &sec, (void **)&pStk_other))
!= HandleError_None)
{
return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl_other, herr);
}

pStk_this->pCurRoot.front()->RecursiveMergeKeyValues(pStk_other->pCurRoot.front());

return 1;

}

static cell_t KeyValues_Import(IPluginContext *pContext, const cell_t *params)
{
// This version takes (dest, src). The original is (src, dest).
Expand Down Expand Up @@ -1256,6 +1284,7 @@ REGISTER_NATIVES(keyvaluenatives)
{"KeyValues.ExportToFile", smn_KeyValuesToFile},
{"KeyValues.ExportToString", smn_KeyValuesToString},
{"KeyValues.ExportLength.get", smn_KeyValuesExportLength},
{"KeyValues.Merge", KeyValues_Merge},

{NULL, NULL}
};
6 changes: 6 additions & 0 deletions plugins/include/keyvalues.inc
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ methodmap KeyValues < Handle
// @param id Id of the current section.
// @return True on success, false on failure.
public native bool GetSectionSymbol(int &id);

// Merge from the current position of another KeyValues into the current
// position of this one.
//
// @param other KeyValues Handle to merge from.
public native void Merge(KeyValues other);
};

/**
Expand Down
Loading