Adding assoc arrays
This commit is contained in:
parent
a7800a6d49
commit
d092ed31dc
|
@ -53,9 +53,8 @@ public:
|
||||||
return SFallScriptValue(0);
|
return SFallScriptValue(0);
|
||||||
};
|
};
|
||||||
if (index == -1) { // special index to indicate if array is associative
|
if (index == -1) { // special index to indicate if array is associative
|
||||||
throw(std::invalid_argument("Not implemented yet"));
|
return SFallScriptValue(0);
|
||||||
};
|
};
|
||||||
// TODO: assoc
|
|
||||||
return SFallScriptValue(index);
|
return SFallScriptValue(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,25 +104,24 @@ public:
|
||||||
|
|
||||||
ProgramValue GetArrayKey(int index)
|
ProgramValue GetArrayKey(int index)
|
||||||
{
|
{
|
||||||
// if (index < -1 || index > size()) {
|
if (index < -1 || index > size()) {
|
||||||
// return SFallScriptValue(0);
|
return SFallScriptValue(0);
|
||||||
// };
|
};
|
||||||
// if (index == -1) { // special index to indicate if array is associative
|
if (index == -1) { // special index to indicate if array is associative
|
||||||
// throw(std::invalid_argument("Not implemented yet"));
|
return SFallScriptValue(1);
|
||||||
// };
|
};
|
||||||
// // TODO: assoc
|
|
||||||
// return SFallScriptValue(index);
|
return keys[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgramValue GetArray(const SFallScriptValue& key)
|
ProgramValue GetArray(const SFallScriptValue& key)
|
||||||
{
|
{
|
||||||
// TODO assoc
|
auto iter = map.find(key);
|
||||||
|
if (iter == map.end()) {
|
||||||
|
return SFallScriptValue(0);
|
||||||
|
};
|
||||||
|
|
||||||
// auto element_index = key.asInt();
|
return iter->second;
|
||||||
// if (element_index < 0 || element_index >= size()) {
|
|
||||||
// return SFallScriptValue(0);
|
|
||||||
// };
|
|
||||||
// return values[element_index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetArray(const SFallScriptValue& key, const SFallScriptValue& val, bool allowUnset)
|
void SetArray(const SFallScriptValue& key, const SFallScriptValue& val, bool allowUnset)
|
||||||
|
|
|
@ -25,7 +25,6 @@ SFallScriptValue::SFallScriptValue(ProgramValue& value)
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case VALUE_TYPE_DYNAMIC_STRING:
|
case VALUE_TYPE_DYNAMIC_STRING:
|
||||||
case VALUE_TYPE_STRING:
|
case VALUE_TYPE_STRING:
|
||||||
// TODO: Copy string
|
|
||||||
pointerValue = value.pointerValue;
|
pointerValue = value.pointerValue;
|
||||||
break;
|
break;
|
||||||
case VALUE_TYPE_PTR:
|
case VALUE_TYPE_PTR:
|
||||||
|
@ -67,4 +66,24 @@ int SFallScriptValue::asInt() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SFallScriptValue::operator<(SFallScriptValue const& other) const
|
||||||
|
{
|
||||||
|
if (opcode != other.opcode) {
|
||||||
|
return opcode < other.opcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (opcode) {
|
||||||
|
case VALUE_TYPE_DYNAMIC_STRING:
|
||||||
|
case VALUE_TYPE_STRING:
|
||||||
|
case VALUE_TYPE_PTR:
|
||||||
|
return pointerValue < other.pointerValue;
|
||||||
|
case VALUE_TYPE_INT:
|
||||||
|
return integerValue < other.integerValue;
|
||||||
|
case VALUE_TYPE_FLOAT:
|
||||||
|
return floatValue < other.floatValue;
|
||||||
|
default:
|
||||||
|
throw(std::exception());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -17,6 +17,8 @@ public:
|
||||||
bool isFloat() const;
|
bool isFloat() const;
|
||||||
bool isPointer() const;
|
bool isPointer() const;
|
||||||
int asInt() const;
|
int asInt() const;
|
||||||
|
|
||||||
|
bool operator<(SFallScriptValue const& other) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue