Fixes for setting to tables not working properly
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
62be1c78f3
commit
256244eabb
|
@ -18,11 +18,8 @@ namespace Porygon::Evaluation {
|
||||||
|
|
||||||
void Porygon::Evaluation::TableEvalValue::SetIndexValue(const Porygon::Utilities::HashedString *key,
|
void Porygon::Evaluation::TableEvalValue::SetIndexValue(const Porygon::Utilities::HashedString *key,
|
||||||
const Porygon::Evaluation::EvalValue *value) const {
|
const Porygon::Evaluation::EvalValue *value) const {
|
||||||
auto insert = _table->insert({*key, value});
|
delete this->_table->operator[](*key).Take();
|
||||||
if (!insert.second) {
|
this->_table->operator[](*key) = value;
|
||||||
_table->at(*key).ClearAssign(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Porygon::Evaluation::Iterator *Porygon::Evaluation::NumericTableEvalValue::GetKeyIterator() const {
|
Porygon::Evaluation::Iterator *Porygon::Evaluation::NumericTableEvalValue::GetKeyIterator() const {
|
||||||
|
|
|
@ -78,10 +78,8 @@ namespace Porygon::Evaluation {
|
||||||
inline void SetIndexValue(const EvalValue *key, const EvalValue* value) const final {
|
inline void SetIndexValue(const EvalValue *key, const EvalValue* value) const final {
|
||||||
auto hash = key->GetHashCode();
|
auto hash = key->GetHashCode();
|
||||||
auto lookup = Utilities::HashedString::CreateLookup(hash);
|
auto lookup = Utilities::HashedString::CreateLookup(hash);
|
||||||
auto insert = _table->insert({lookup, value});
|
delete this->_table->operator[](lookup).Take();
|
||||||
if (!insert.second) {
|
this->_table->operator[](lookup) = value;
|
||||||
_table->at(lookup).ClearAssign(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
|
|
@ -95,7 +95,7 @@ namespace Porygon{
|
||||||
return _isContentAware;
|
return _isContentAware;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<const ScriptType> GetIndexedType(shared_ptr<const ScriptType> indexer) const override {
|
[[nodiscard]] shared_ptr<const ScriptType> GetIndexedType(shared_ptr<const ScriptType> indexer) const override {
|
||||||
if (_tableType == TableType::Unknown)
|
if (_tableType == TableType::Unknown)
|
||||||
return ScriptType::AnyType;
|
return ScriptType::AnyType;
|
||||||
else if (_tableType == TableType::StringKeyed){
|
else if (_tableType == TableType::StringKeyed){
|
||||||
|
@ -116,8 +116,13 @@ namespace Porygon{
|
||||||
|
|
||||||
[[nodiscard]] shared_ptr<const ScriptType> GetIndexedType(uint32_t hash) const override {
|
[[nodiscard]] shared_ptr<const ScriptType> GetIndexedType(uint32_t hash) const override {
|
||||||
auto lookup = Utilities::HashedString::CreateLookup(hash);
|
auto lookup = Utilities::HashedString::CreateLookup(hash);
|
||||||
|
if (GetContentTypes()->find(lookup) != GetContentTypes()->end()){
|
||||||
return GetContentTypes()->at(lookup);
|
return GetContentTypes()->at(lookup);
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
return ScriptType::AnyType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] inline ContentTypes GetContentTypes() const{
|
[[nodiscard]] inline ContentTypes GetContentTypes() const{
|
||||||
return std::get<ContentTypes>(_contentTypes);
|
return std::get<ContentTypes>(_contentTypes);
|
||||||
|
@ -160,6 +165,13 @@ namespace Porygon{
|
||||||
GetContentTypes()->insert({key, val});
|
GetContentTypes()->insert({key, val});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (_tableType == TableType::Unknown){
|
||||||
|
auto t = const_cast<TableScriptType*>(this);
|
||||||
|
if (indexer->GetClass() == TypeClass::Number){
|
||||||
|
t->_tableType = TableType ::Numerical;
|
||||||
|
t->_valueType = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetIndexValue(Utilities::HashedString indexer, shared_ptr<const ScriptType> val) const override {
|
void SetIndexValue(Utilities::HashedString indexer, shared_ptr<const ScriptType> val) const override {
|
||||||
|
|
|
@ -184,5 +184,22 @@ end
|
||||||
delete runCount;
|
delete runCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Generic for loop next", "[integration]" ) {
|
||||||
|
auto script = Script::Create(uR"(
|
||||||
|
local table = {1, 3, 5, 7, 9}
|
||||||
|
result = 0
|
||||||
|
for i,v in table do
|
||||||
|
if i == 3 then next end
|
||||||
|
result = result + v
|
||||||
|
end
|
||||||
|
)");
|
||||||
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
|
script->Evaluate();
|
||||||
|
auto var = script->GetVariable(u"result");
|
||||||
|
REQUIRE(var->EvaluateInteger() == 20);
|
||||||
|
delete script;
|
||||||
|
delete var;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -111,6 +111,24 @@ return table[1]
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "assign nil to a string table", "[integration]" ) {
|
||||||
|
Script* script = Script::Create(
|
||||||
|
R"(
|
||||||
|
table = {'bla', 'test', 'foo', 'bar'}
|
||||||
|
table[3] = nil
|
||||||
|
return table
|
||||||
|
)");
|
||||||
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
|
auto variable = script->Evaluate();
|
||||||
|
REQUIRE(variable.Get() != nullptr);
|
||||||
|
auto lookup = Utilities::HashedString::CreateLookup(3);
|
||||||
|
auto tableValue = variable->IndexValue(&lookup);
|
||||||
|
REQUIRE(tableValue->GetTypeClass() == TypeClass::Nil);
|
||||||
|
delete script;
|
||||||
|
delete tableValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue