This commit is contained in:
@@ -51,7 +51,7 @@ namespace Porygon::UserData {
|
||||
return indexer->operator==(_keyType);
|
||||
}
|
||||
|
||||
[[nodiscard]] shared_ptr<const ScriptType> GetIndexedType(const ScriptType* indexer) const final{
|
||||
[[nodiscard]] shared_ptr<const ScriptType> GetIndexedType(shared_ptr<const ScriptType> indexer) const final{
|
||||
return _valueType;
|
||||
}
|
||||
|
||||
@@ -70,6 +70,15 @@ namespace Porygon::UserData {
|
||||
[[nodiscard]] bool IsCountable() const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool CanSetIndexValue(shared_ptr<const ScriptType> indexer, shared_ptr<const ScriptType> val) const override {
|
||||
if (indexer->CastableTo(_keyType, false) == CastResult::InvalidCast)
|
||||
return false;
|
||||
if (val->CastableTo(_valueType, false) == CastResult::InvalidCast)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ namespace Porygon::UserData{
|
||||
: GenericFunctionOption(std::move(returnType), std::move(parameterTypes)) {
|
||||
|
||||
}
|
||||
static UserDataFunctionOption* FromRawPointers(const ScriptType* returnType, vector<const ScriptType*> parameterTypes){
|
||||
static UserDataFunctionOption* FromRawPointers(ScriptType* returnType, vector<ScriptType*> parameterTypes){
|
||||
auto rt = shared_ptr<const ScriptType>(returnType);
|
||||
auto p = vector<shared_ptr<const ScriptType>>(parameterTypes.size());
|
||||
for (size_t i = 0; i < parameterTypes.size(); i++){
|
||||
p[i] = shared_ptr<const ScriptType>(parameterTypes[i]);
|
||||
p[i] = shared_ptr<ScriptType>(parameterTypes[i]);
|
||||
}
|
||||
return new UserDataFunctionOption(rt, p);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Porygon::UserData {
|
||||
auto str = dynamic_cast<const StringScriptType*>(indexer);
|
||||
if (!str->IsKnownAtBind())
|
||||
return false;
|
||||
return _userData->Get()->ContainsField(str->GetHashValue());
|
||||
return _userData->Get()->ContainsField(str->GetHashValue().GetHash());
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool CanBeIndexedWithIdentifier(uint32_t hash) const final {
|
||||
@@ -47,10 +47,10 @@ namespace Porygon::UserData {
|
||||
return _userData->Get()->GetField(id);
|
||||
}
|
||||
|
||||
shared_ptr<const ScriptType> GetIndexedType(const ScriptType *indexer) const final {
|
||||
auto stringKey = dynamic_cast<const StringScriptType*>(indexer);
|
||||
shared_ptr<const ScriptType> GetIndexedType(shared_ptr<const ScriptType> indexer) const final {
|
||||
auto stringKey = dynamic_pointer_cast<const StringScriptType>(indexer);
|
||||
if (stringKey->IsKnownAtBind()) {
|
||||
return _userData->Get()->GetField(stringKey->GetHashValue())->GetType();
|
||||
return _userData->Get()->GetField(stringKey->GetHashValue().GetHash())->GetType();
|
||||
}
|
||||
throw "TODO: indexing with dynamic keys";
|
||||
}
|
||||
@@ -72,6 +72,30 @@ namespace Porygon::UserData {
|
||||
return s.str();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool CanSetIndexValue(shared_ptr<const ScriptType> indexer, shared_ptr<const ScriptType> val) const override {
|
||||
if (indexer->GetClass() != TypeClass::String)
|
||||
return false;
|
||||
auto s = dynamic_pointer_cast<const StringScriptType>(indexer);
|
||||
if (!s->IsKnownAtBind())
|
||||
return false;
|
||||
auto hash = s->GetHashValue();
|
||||
auto ud = _userData->Get();
|
||||
if (!ud->ContainsField(hash.GetHash()))
|
||||
return false;
|
||||
auto field = _userData->Get()->GetField(hash.GetHash());
|
||||
return (val->CastableTo(field->GetType(), false) != CastResult::InvalidCast);
|
||||
|
||||
}
|
||||
|
||||
[[nodiscard]] bool CanSetIndexValue(Utilities::HashedString indexer, shared_ptr<const ScriptType> val) const override {
|
||||
auto ud = _userData->Get();
|
||||
if (ud->ContainsField(indexer.GetHash()))
|
||||
return false;
|
||||
auto field = _userData->Get()->GetField(indexer.GetHash());
|
||||
return (val->CastableTo(field->GetType(), false) != CastResult::InvalidCast);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user