MTROPOLIS: Handle direct assignment to variables

This commit is contained in:
elasota 2022-05-27 21:42:06 -04:00 committed by Eugene Sandulenko
parent 1975bd6b3c
commit 547e02c749

View File

@ -1712,6 +1712,17 @@ void DynamicValueWriteBoolHelper::create(bool *boolValue, DynamicValueWriteProxy
DynamicValueWriteBoolHelper DynamicValueWriteBoolHelper::_instance;
MiniscriptInstructionOutcome DynamicValueWriteObjectHelper::write(MiniscriptThread *thread, const DynamicValue &value, void *objectRef, uintptr ptrOrOffset) const {
RuntimeObject *obj = static_cast<RuntimeObject *>(objectRef);
if (obj->isModifier() && static_cast<Modifier *>(obj)->isVariable()) {
VariableModifier *var = static_cast<VariableModifier *>(obj);
if (var->varSetValue(thread, value))
return kMiniscriptInstructionOutcomeContinue;
else {
thread->error("Failed to assign value to variable");
return kMiniscriptInstructionOutcomeFailed;
}
}
thread->error("Can't write to read-only object value");
return kMiniscriptInstructionOutcomeFailed;
}
@ -2667,6 +2678,22 @@ MiniscriptInstructionOutcome Structural::writeRefAttribute(MiniscriptThread *thr
return kMiniscriptInstructionOutcomeContinue;
}
// Attempt to resolve as a child object
// Modifiers are first, then structural
for (const Common::SharedPtr<Modifier> &modifier : _modifiers) {
if (caseInsensitiveEqual(modifier->getName(), attrib)) {
DynamicValueWriteObjectHelper::create(modifier.get(), result);
return kMiniscriptInstructionOutcomeContinue;
}
}
for (const Common::SharedPtr<Structural> &child : _children) {
if (caseInsensitiveEqual(child->getName(), attrib)) {
DynamicValueWriteObjectHelper::create(child.get(), result);
return kMiniscriptInstructionOutcomeContinue;
}
}
return RuntimeObject::writeRefAttribute(thread, result, attrib);
}