Implements indexing with period identifier style (`foo.bar`)
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-17 15:45:33 +02:00
parent d06b04cae9
commit d91caa7f32
17 changed files with 207 additions and 32 deletions

View File

@@ -18,7 +18,7 @@ public:
_userData = std::move(ud);
}
bool CanBeIndexedWith(ScriptType* indexer) final{
const bool CanBeIndexedWith(ScriptType* indexer) const final{
if (indexer->GetClass() != TypeClass ::String){
return false;
}
@@ -28,17 +28,25 @@ public:
return _userData->ContainsField(str->GetHashValue());
}
const bool CanBeIndexedWithIdentifier(uint32_t hash) const final{
return true;
}
UserDataField* GetField(uint32_t id){
return _userData -> GetField(id);
}
shared_ptr<ScriptType> GetIndexedType(ScriptType* indexer) final{
const shared_ptr<ScriptType> GetIndexedType(ScriptType* indexer) const final{
auto stringKey = (StringScriptType*)indexer;
if (stringKey->IsKnownAtBind()){
return _userData->GetField(stringKey->GetHashValue())->GetType();
}
throw "TODO: indexing with dynamic keys";
}
const shared_ptr<ScriptType> GetIndexedType(uint32_t hash) const final{
return _userData->GetField(hash)->GetType();
}
};

View File

@@ -46,6 +46,11 @@ public:
return shared_ptr<EvalValue>(field->Get(_obj));
}
shared_ptr<EvalValue> IndexValue(uint32_t hash) final{
auto field = _userData->GetField(hash);
return shared_ptr<EvalValue>(field->Get(_obj));
}
void SetIndexValue(EvalValue *key, shared_ptr<EvalValue> value) final{
auto fieldId = key->GetHashCode();
auto field = _userData->GetField(fieldId);