Adding vscript GetKeyValue vscript

Intended usage:
```
int nIterator = -1;
ScriptVariant_t key, value;
while ((nIterator = pScriptVM->GetKeyValue(table, nIterator, &key, &value)) != -1)
{
    printVariant(key);
    Msg("=");
    printVariant(value);
    Msg("\n");

    pScriptVM->ReleaseValue(key);
    pScriptVM->ReleaseValue(value);
}
```
This commit is contained in:
James Mitchell 2020-05-24 14:54:46 +10:00
parent 2363a22e3e
commit 3c6c5c1d81

View File

@ -1837,13 +1837,40 @@ int SquirrelVM::GetNumTableEntries(HSCRIPT hScope)
int SquirrelVM::GetKeyValue(HSCRIPT hScope, int nIterator, ScriptVariant_t* pKey, ScriptVariant_t* pValue) int SquirrelVM::GetKeyValue(HSCRIPT hScope, int nIterator, ScriptVariant_t* pKey, ScriptVariant_t* pValue)
{ {
SquirrelSafeCheck safeCheck(vm_); SquirrelSafeCheck safeCheck(vm_);
// TODO: How does this work does it expect to output to pKey and pValue as an array from nIterator
// elements or does it expect nIterator to be an index in hScrope, if so how does that work without if (hScope)
// without depending on squirrel internals not public API for getting the iterator (which is opaque) {
// or do you iterate until that point and output the value? If it should be iterator then this should Assert(hScope != INVALID_HSCRIPT);
// be a HSCRIPT for ease of use. HSQOBJECT* scope = (HSQOBJECT*)hScope;
Assert(!"GetKeyValue is not implemented"); sq_pushobject(vm_, *scope);
return 0; }
else
{
sq_pushroottable(vm_);
}
if (nIterator == -1)
{
sq_pushnull(vm_);
}
else
{
sq_pushinteger(vm_, nIterator);
}
SQInteger nextiter = -1;
if (SQ_SUCCEEDED(sq_next(vm_, -2)))
{
if (pKey) getVariant(vm_, -2, *pKey);
if (pValue) getVariant(vm_, -1, *pValue);
sq_getinteger(vm_, -3, &nextiter);
sq_pop(vm_, 2);
}
sq_pop(vm_, 2);
return nextiter;
} }
bool SquirrelVM::GetValue(HSCRIPT hScope, const char* pszKey, ScriptVariant_t* pValue) bool SquirrelVM::GetValue(HSCRIPT hScope, const char* pszKey, ScriptVariant_t* pValue)