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,53 +613,47 @@ 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)
{
if (std::holds_alternative<SQBool>(value)) { switch (type) {
sq_pushbool(vm, std::get<SQBool>(value)); case SQSL_ARRAY:
return true; sq_newarray(this->vm, 0);
} while (LoadObjects(this->vm, this->data)) {
sq_arrayappend(this->vm, -2);
switch (std::get<SQSaveLoadType>(value)) {
case SQSL_ARRAY: {
sq_newarray(vm, 0);
while (LoadObjects(vm, data)) {
sq_arrayappend(vm, -2);
/* The value is popped from the stack by squirrel. */ /* The value is popped from the stack by squirrel. */
} }
return true; return true;
}
case SQSL_TABLE: { case SQSL_TABLE:
sq_newtable(vm); sq_newtable(this->vm);
while (LoadObjects(vm, data)) { while (LoadObjects(this->vm, this->data)) {
LoadObjects(vm, data); LoadObjects(this->vm, this->data);
sq_rawset(vm, -3); sq_rawset(this->vm, -3);
/* The key (-2) and value (-1) are popped from the stack by squirrel. */ /* The key (-2) and value (-1) are popped from the stack by squirrel. */
} }
return true; return true;
}
case SQSL_NULL: { case SQSL_NULL:
sq_pushnull(vm); sq_pushnull(this->vm);
return true; return true;
}
case SQSL_ARRAY_TABLE_END: { case SQSL_ARRAY_TABLE_END:
return false; return false;
}
default: NOT_REACHED(); default: NOT_REACHED();
} }
} }
};
return std::visit(visitor{vm, data}, value);
}
/* static */ void ScriptInstance::LoadEmpty() /* static */ void ScriptInstance::LoadEmpty()
{ {