Codechange: Use std::visit for ScriptDataVariant.

This commit is contained in:
Peter Nelson 2024-11-19 13:56:57 +00:00 committed by Peter Nelson
parent d875ac8947
commit 43da3e7693

View File

@ -613,52 +613,46 @@ bool ScriptInstance::IsPaused()
ScriptDataVariant value = data->front(); ScriptDataVariant value = data->front();
data->pop_front(); data->pop_front();
if (std::holds_alternative<SQInteger>(value)) { struct visitor {
sq_pushinteger(vm, std::get<SQInteger>(value)); HSQUIRRELVM vm;
return true; ScriptData *data;
}
if (std::holds_alternative<std::string>(value)) { bool operator()(const SQInteger &value) { sq_pushinteger(this->vm, value); return true; }
sq_pushstring(vm, std::get<std::string>(value), -1); bool operator()(const std::string &value) { sq_pushstring(this->vm, value, -1); return true; }
return true; bool operator()(const SQBool &value) { sq_pushbool(this->vm, value); return true; }
} bool operator()(const SQSaveLoadType &type)
{
switch (type) {
case SQSL_ARRAY:
sq_newarray(this->vm, 0);
while (LoadObjects(this->vm, this->data)) {
sq_arrayappend(this->vm, -2);
/* The value is popped from the stack by squirrel. */
}
return true;
if (std::holds_alternative<SQBool>(value)) { case SQSL_TABLE:
sq_pushbool(vm, std::get<SQBool>(value)); sq_newtable(this->vm);
return true; while (LoadObjects(this->vm, this->data)) {
} LoadObjects(this->vm, this->data);
sq_rawset(this->vm, -3);
/* The key (-2) and value (-1) are popped from the stack by squirrel. */
}
return true;
switch (std::get<SQSaveLoadType>(value)) { case SQSL_NULL:
case SQSL_ARRAY: { sq_pushnull(this->vm);
sq_newarray(vm, 0); return true;
while (LoadObjects(vm, data)) {
sq_arrayappend(vm, -2); case SQSL_ARRAY_TABLE_END:
/* The value is popped from the stack by squirrel. */ return false;
default: NOT_REACHED();
} }
return true;
} }
};
case SQSL_TABLE: { return std::visit(visitor{vm, data}, value);
sq_newtable(vm);
while (LoadObjects(vm, data)) {
LoadObjects(vm, data);
sq_rawset(vm, -3);
/* The key (-2) and value (-1) are popped from the stack by squirrel. */
}
return true;
}
case SQSL_NULL: {
sq_pushnull(vm);
return true;
}
case SQSL_ARRAY_TABLE_END: {
return false;
}
default: NOT_REACHED();
}
} }
/* static */ void ScriptInstance::LoadEmpty() /* static */ void ScriptInstance::LoadEmpty()